GoAccess (goaccess.io, github) is a tool that analyses server logs and gives real-time statistics on network traffic. It took me some time to figure out exactly how to get the real-time websocket server working through Nginx, so I’m just sharing my configuration here.
Install via your package manager, e.g. sudo pacman -S goaccess
on Arch.
The result will look like this.

Figure 1: (Click it to open in new tab.)
1 Nginx setup Link to heading
First we make sure that nginx logs all requests. I have a bunch of nginx
server
blocks, so I’m logging the curiouscoding.nl
logs to their own file:
|
|
2 GoAccess configuration Link to heading
Now we’ll do some configuration to parse nginx
logs. I’m not quite sure all
of these are strictly needed, but this is what I currently have. See the full
file on your system for docs for each option.
|
|
You should now be able to run goaccess --output /tmp/index.html
on your
server. You can either cp
it somewhere into the public/
directory of your
site or scp
it to your local machine to view it in a browser.
3 Systemd setup Link to heading
We’d like to have goaccess running in the background.
First, create the goaccess
user:
|
|
Then, create /srv/nginx/goaccess
, owned by the goaccess
user, which is where
we’ll host the static index.html
page.
|
|
Now, we can crate a systemd service:
|
|
Now start and enable the service.
|
|
This should now write /srv/nginx/goaccess/index.html
.
4 Serving the static file Link to heading
Now we want to view /srv/nginx/goaccess/index.html
. Add the following server
block:
|
|
Now sudo systemctl restart nginx
and go to goaccess.curiouscoding.nl
to see
the generated report.
5 Serving live statistics Link to heading
By default, we just see the generated index.html
file, and we have to restart
goaccess.service
to regenerate it. But GoAccess also supports a websocket
server that can show real-time statistics. This was slightly more tricky to get
working, but ends up being very nice!
Heads-up: while the static page shows up to 366 table rows per panel, the live
view only shows up to 50 to save data. See
this issue for possible workarounds if you want to see the full data anyway.
(To work around this, I created a second goaccess-static
one-shot
systemd service that drops
the --realtime-html
flag and the Restart
and RestartSec
lines, that writes
to .../index-static.html
.)
First, make sure that you add the --real-time-html
flag to the systemd
service, as I already did in Code Snippet 3.
Then, update the goaccess configuration with:
|
|
Also update the nginx configuration for goaccess.curiouscoding.nl
like this:
|
|
Now sudo systemctl restart nginx
, and go to goaccess.curiouscoding.nl
. You
should see a green dot in the top left indicating the websocket server is working.
6 GeoIP database Link to heading
If you want to see where your users are coming from, you’ll need a database for it.
As linked in goaccess.conf
, I went to
https://db-ip.com/db/download/ip-to-city-lite and downloaded the ‘IP to city
lite MMDB
’. Copy that to /usr/local/share/GeoIP
, and then add the following
to the goaccess configuration:
|
|
Now sudo systemctl restart goaccess
and refresh goaccess.curiouscoding.nl
.
