Using Goaccess to Replace Google Analytics feat. Caddy and Docker

Apr 5, 2018
Goaccess is a log analyser that can be used to visualise your website traffic.

Why use it?

It has three advantages compared to traditional web analytics like Google Analytics or Piwik.
  1. Goaccess analyses the web server logs directly, so it doesn’t need to load javascript file. This will speed up the page load significantly.
  1. All the data is stored in your server, not on Google’s server. You own it.
  1. You can access it either using CLI or opening the generated html file.


  1. Harder to setup; you can’t just copy paste the javascript loading codes to <HEAD> section.
  1. Very basic tracking mechanism. You can’t set customer sales funnel or drill down on granular data.
For my use case, where I just wanted to know the unique visitors number, referrer, etc. It is good enough compromise.

Dockerizing Goaccess with Caddy

The official Docker image contains good tutorial on how to use it.
The first step is to either build and run it, or just to use docker-compose. Any self-respecting Docker user will use the compose, so let’s take a look.
version: '2'
		   # other stuff
             - ./docker/caddy/logs:/etc/logs <- IMPORTANT
             - ./docker/goaccess/.html:/site/goaccess <- To view it on subdomain
         image: allinurl/goaccess
         restart: unless-stopped
             - ./docker/goaccess/data:/srv/data
             - ./docker/goaccess/.html:/srv/report
             - ./docker/caddy/logs:/srv/logs
./docker/caddy/logs:/etc/logs This will share save the Caddy server logs to system disk folder, which in turn will be shared and read by Goaccess Docker image.
./docker/goaccess/.html:/site/goaccess This will share let Caddy server to serve the generated Goaccess html file on a subdomain
The Goaccess compose script is very standard, just following the default config on the Docker hub page.
in Caddyfile, we just need to add this line to your desired host server to save the generated logs to disk:
log / /etc/logs/requests.log "{combined}"
This means we are logging all request (/) into /etc/logs/requests.log using the "{combined}" format. Combined is used here because it contains referrer and user agent.
You can read more information on the log syntax on the official docs.
If you wanted to access the generated html file on a subdomain, just add this to the Caddyfile: {
     basicauth / admin password
     root /site/goaccess
This will serve the generated index.html on the subdomain. Basic auth is important here if you don’t want just anyone to be able to see your analytics.
We need to specify the config file for Goaccess to tell it which file to load, like so:
 log-format COMBINED
 log-file /srv/logs/requests.log
 output /srv/report/index.html
 real-time-html true
COMBINED is used here because we tell Caddy server to generate Combined log format.
You are done, just run docker-compose up -d to spin up Caddy and Goaccess.
When you access you should see something like:
notion image
I hope this helps!

© Victor Augusteo 2021 - 2024