LLI Wiki — My Digital Knowledge Base

GoAccess: real-time nginx report over HTTPS with basic auth

Analyse nginx logs with GoAccess in terminal or HTML mode, served over TLS with basic auth and Certbot.

GoAccess is a log analyser that produces a live terminal dashboard or an HTML report from web server access logs. This article shows how to use it with nginx logs, publish the report over HTTPS and protect it with basic authentication.

Terminal mode

Analyse current and rotated (gzipped) logs at once:

sudo zcat --force /var/log/nginx/access.log* | goaccess -

Follow the live log:

tail -f /var/log/nginx/access.log | goaccess -

Generate a static HTML report from all logs:

sudo zcat --force /var/log/nginx/access.log* | goaccess - -a > /usr/share/webapps/goaccess/report.html

Real-time HTML report

GoAccess can serve a self-updating HTML report with its built-in WebSocket server (default port 7890). Here with TLS:

sudo goaccess /var/log/nginx/access.log \
  -o /usr/share/webapps/goaccess/report.html \
  --log-format=COMBINED --real-time-html \
  --ssl-cert=/etc/letsencrypt/live/goaccess.example.com/fullchain.pem \
  --ssl-key=/etc/letsencrypt/live/goaccess.example.com/privkey.pem

The report is then available at https://goaccess.example.com/report.html.

Protect the report with basic authentication

Create a password file (the nginx-passwd helper from the source note; htpasswd from apache2-utils works the same way):

sudo nginx-passwd -f /etc/nginx/.htpasswd admin

Create /etc/nginx/conf.d/goaccess.conf:

server {
    server_name goaccess.example.com;
    root /usr/share/webapps/goaccess;
    index index.html;

    location / {
        auth_basic "Restricted Area";
        auth_basic_user_file /etc/nginx/.htpasswd;
        try_files $uri $uri/ =404;
    }

    # Optional dedicated logs
    access_log /var/log/nginx/goaccess_access.log;
    error_log /var/log/nginx/goaccess_error.log;

    # SSL (managed by Certbot)
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/goaccess.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/goaccess.example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    ssl_trusted_certificate /etc/letsencrypt/live/goaccess.example.com/chain.pem;
    ssl_stapling on;
    ssl_stapling_verify on;
}

server {
    # Permanent redirect HTTP to HTTPS
    listen 80;
    server_name goaccess.example.com;
    return 301 https://$host$request_uri;
}

Obtain the certificate

sudo certbot --nginx --agree-tos --redirect --staple-ocsp --email admin@example.com -d goaccess.example.com

Notes

Mastodon LLIMastodon SocialFosstodon