Install GoAccess Web log analyzer on Ubuntu Server 20.04 LTS

May 21, 2020

Why

I did a massive upgrade to my personal website and decided to experiment an alternative to Google Analytics. My idea is to have insights (most visited pages, operating systems, browsers and referrals) about the visitors without any client-side code and cookie.

Google Analytics is still running on my website so I am able to compare the results of both solutions (assuming Google Analytics more accurate).

I duckDucked looking for a tool that can help me to reach this goal and the one that captured my attention was GoAccess.

Installation

The first thing to do, it is adding the Official GoAccess' Debian/Ubuntu Repository to our repositories. The version available on standard repository is really old. We have to follow the steps in the GoAccess documentation

$ echo "deb http://deb.goaccess.io/ $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list.d/goaccess.list
$ wget -O - https://deb.goaccess.io/gnugpg.key | sudo apt-key add -
$ sudo apt-get update

After that we are able install the last available version (at the time of writing this post was 1.4)

$ sudo apt-get install goaccess

Configuration

Add user to adm group

It is a good idea to add the current user to adm group so we do not have to prefix sudo to get permission to access. Remember to replace myuser with your own Ubuntu user.

$ sudo usermod -g adm myuser

Firewall

By default GoAccess listens on port 7890 for the WebSocket server. Ensure this port is opened. If you, like me, are running your server on DigitalOcean, you have to:

  1. open your project and click on Networking (section Manage)

  2. click on Firewalls tab and then click on your domain

  3. add a Custom rule

    • Protocol: TCP

    • Ports: 7890

    • Sources: All IPv4, All IPv6

Run

Now that everything is set up we can run GoAccess. We can create a small script with our preferred configuration. The one below

  1. ignores crawlers (--ignore-crawlers)

  2. uses combined (the default for NGINX) log format (--log-format)

  3. displays real OS names (--real-os)

  4. outputs a realtime HTML dashboard report.html (-o and --real-time-html)

  5. runs GoAccess as daemon (--daemonize)

#!/bin/bash

clear

echo ""
echo "Starting GoAccess as daemon ..."
echo ""

goaccess /var/log/nginx/www.example.com-access.log \
    -o /var/www/www.example.com/report.html \
    --ignore-crawlers \
    --log-format=COMBINED \
    --real-os \
    --real-time-html \
    --ssl-cert=/etc/letsencrypt/live/example.com/fullchain.pem \
    --ssl-key=/etc/letsencrypt/live/example.com/privkey.pem \
    --daemonize

echo ""
echo "Running in background"
echo ""

the options --ssl-cert and --ssl-key need because my server works over HTTPS.

Final thoughts

I just deployed GoAccess, so it is still too early to say if it is exactly what I am looking for. That said, watching the the GoAccess dashboard I think I'm really close to what I need by adding some conditional logging to my NGINX configuration.


A photo of Elia Contini
Written by
Elia Contini
Sardinian UX engineer and a Front-end web architect based in Ticino, Switzerland. Marathoner, traveller, wannabe nature photographer.