How to Install and Use GoAccess on Ubuntu Server: Real-Time Nginx Log Analysis via Web UI

Ubuntu tutorial - IT technology blog
Ubuntu tutorial - IT technology blog

Is your website suddenly slowing down or showing signs of request spam? Sitting there running tail -f /var/log/nginx/access.log and squinting at lines of text in the terminal is a huge waste of time.

If you only have a 1 GB RAM VPS and don’t want to spin up a full ELK Stack or Grafana cluster that eats up several GBs of memory, GoAccess is a much lighter alternative. Written in C, this tool uses only around 15–30 MB of RAM yet parses tens of thousands of log lines per second and outputs directly to a WebSocket-powered Web Dashboard.

Quick start: Install and view Nginx logs in 5 minutes

Ubuntu’s default apt repository often ships a fairly outdated version of GoAccess (such as 1.5.x on Ubuntu 22.04) that lacks important WebSocket fixes. It’s best to install the latest release directly from the official GoAccess repository.

Run the following 3 commands in order to add the GPG key, configure the repository, and install GoAccess:

wget -O - https://deb.goaccess.io/gnugpg.key | gpg --dearmor | sudo tee /usr/share/keyrings/goaccess.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/goaccess.gpg arch=$(dpkg --print-architecture)] https://deb.goaccess.io/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/goaccess.list
sudo apt update && sudo apt install goaccess -y

Verify the installed version:

goaccess --version

To immediately generate a real-time web report from Nginx’s default log file, run this command:

sudo goaccess /var/log/nginx/access.log \
  -o /var/www/html/report.html \
  --log-format=COMBINED \
  --real-time-html \
  --daemonize

That’s it for the setup. As long as Nginx is serving the /var/www/html directory and port 7890 is open in your firewall, opening http://your-server-ip/report.html in your browser will show live charts updating with every incoming request.

Deep dive: How GoAccess parses logs and pushes real-time data

Now that it’s running, let’s break down each parameter you just typed. Understanding how it works under the hood will make it much easier to customize when your server setup gets more complex.

1. Log format (–log-format=COMBINED)

By default, Nginx writes logs in the combined format, which includes client IP, timestamp, HTTP method, URL, status code, response size, Referer, and User-Agent. The --log-format=COMBINED flag tells GoAccess how to parse each of these columns properly.

However, if you have customized log_format in nginx.conf (for example, adding $request_time to measure latency), GoAccess will fail to parse the file. In that case, you’ll need to define a matching log format pattern in /etc/goaccess/goaccess.conf.

2. Real-time WebSocket mechanism (–real-time-html)

Unlike generating a static HTML file, the --real-time-html flag starts a built-in WebSocket server on port 7890. Whenever Nginx writes a new log line to disk, GoAccess reads it immediately and pushes a JSON payload over WebSocket to your browser. That’s why the metrics update live without needing to hit F5.

Paired with it is the --daemonize flag, which keeps the process running in the background so it doesn’t terminate when you close your SSH session.

3. The most useful metrics to watch on the Dashboard

  • Unique visitors per day: Actual unique visitors, filtered by IP address, User-Agent, and access date.
  • Requested Files (URLs): Ranks the most frequently requested paths — one glance tells you which API endpoint or page is getting hammered.
  • 404 Not Found URLs: A list of 404 errors. This is where you’ll easily spot automated bots scanning for vulnerabilities like /wp-login.php, /.env, or /phpmyadmin hundreds of times per minute.
  • HTTP Status Codes: Tracks the ratio of 200, 301, 404, and especially 5xx codes (500, 502, 504) to catch backend overload early.

Advanced: Running GoAccess as a Systemd Service behind Nginx

Using --daemonize is great for quick testing, but it isn’t secure or resilient enough for production. You should turn GoAccess into a systemd service so it starts automatically on reboot, while hiding port 7890 behind Nginx and protecting the stats page with a password.

Step 1: Configure goaccess.conf

Open /etc/goaccess/goaccess.conf, uncomment or append the following lines to the end of the file:

time-format %H:%M:%S
date-format %d/%b/%Y
log-format COMBINED
real-time-html true
ws-url wss://your-domain.com/ws
port 7890
addr 127.0.0.1

Here we bind addr 127.0.0.1 so the WebSocket server only listens locally instead of exposing port 7890 to the public Internet. Also, if your site runs over HTTPS, ws-url must use wss:// to avoid Mixed Content blocks in the browser.

Step 2: Create a Systemd Service for GoAccess

Create a new file at /etc/systemd/system/goaccess.service with the following contents:

[Unit]
Description=GoAccess Real-time Nginx Log Analyzer
After=network.target nginx.service

[Service]
Type=simple
ExecStart=/usr/bin/goaccess /var/log/nginx/access.log -o /var/www/goaccess/index.html -p /etc/goaccess/goaccess.conf
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Create the directory for the HTML output and start the service:

sudo mkdir -p /var/www/goaccess
sudo systemctl daemon-reload
sudo systemctl enable --now goaccess
sudo systemctl status goaccess

Step 3: Proxy WebSocket and add password protection in Nginx

Inside your Nginx server block, add these two location blocks to serve the dashboard at /stats/ with Basic Auth and proxy WebSocket traffic through /ws:

location /stats/ {
    alias /var/www/goaccess/;
    index index.html;
    auth_basic "Restricted Stats";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

location /ws {
    proxy_pass http://127.0.0.1:7890;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400;
}

Next, install apache2-utils to create the /etc/nginx/.htpasswd password file and reload Nginx:

sudo apt install apache2-utils -y
sudo htpasswd -c /etc/nginx/.htpasswd admin
sudo nginx -t && sudo systemctl reload nginx

Now simply visit https://your-domain.com/stats/, log in with the credentials you just created, and you’ll have a real-time dashboard running securely over HTTPS.

Practical tips for production operations

After running GoAccess across various VPS instances, here are a few small tweaks that keep your metrics clean and prevent disk usage from growing out of control:

  • Preserve history across restarts: By default, restarting the service resets all charts to zero. Create a directory with sudo mkdir -p /var/lib/goaccess and add persist true, restore true, and db-path /var/lib/goaccess to /etc/goaccess/goaccess.conf to save state to disk.
  • Cap database size: On a site handling ~100,000 requests/day, the database directory can grow fairly quickly. Add keep-last 30 to your config so GoAccess only retains the last 30 days of data — plenty for comparison without filling up your disk.
  • Analyze older compressed logs (.gz): Need to investigate an incident from last week after logrotate already compressed the logs? Generate a quick static report with: zcat /var/log/nginx/access.log.*.gz | goaccess - --log-format=COMBINED -o /tmp/old-report.html.
  • Filter out search bots to see real traffic: Add ignore-crawlers true to your config (or pass --ignore-crawlers on the CLI) to exclude Googlebot, Bingbot, and other crawlers from visitor stats.
  • Watch 499 errors to catch a slow backend: Don’t just look at page views. Keep an eye on status code 499 (client closed the connection before the server could respond) alongside 502. If 499 spikes, it’s almost certain that your PHP, Node.js, or Python backend is responding too slowly and users are closing the tab out of impatience.
Share: