Installing GoAccess: Real-time Nginx Log Analysis Made Easy to Replace ELK Stack

Monitoring tutorial - IT technology blog
Monitoring tutorial - IT technology blog

Going Beyond the Limits of tail -f

Server administrators are likely no strangers to opening a terminal and typing tail -f /var/log/nginx/access.log. Watching the lines of text fly by looks “serious” and satisfying, but when you need to quickly filter spam IPs, find malicious bots, or identify the most frequent 404 errors, it becomes a true nightmare.

In my experience: don’t try to deploy an ELK stack (Elasticsearch, Logstash, Kibana) just to monitor logs for a few personal blogs. I’ve tried, and the result was 4GB of RAM swallowed in an instant. Sometimes you don’t need a heavy-duty truck just to carry a bag of rice. GoAccess is the agile motorcycle weaving through the traffic jam you’ve been looking for.

Written in C, this tool boasts incredible processing speed. It can crunch 100,000 log lines in seconds. You can view reports directly in the terminal or export them to a real-time HTML dashboard updated via WebSockets.

Installing GoAccess: Done in a Flash

While most Linux distributions include GoAccess, I recommend installing the official version to access the latest features, especially stable WebSocket support.

Ubuntu/Debian OS

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-get update
sudo apt-get install goaccess

CentOS/RHEL OS

sudo yum install goaccess

Type goaccess --version to check. If you see version 1.x or higher, you’re ready to get to work.

Analyzing Logs Directly in the Terminal

This is the fastest way to diagnose server issues immediately after SSHing in. Just point the command to your Nginx log file:

goaccess /var/log/nginx/access.log -c

Once executed, the Log Format Configuration screen will appear. For a standard Nginx config, just press Space to select NCSA Combined Log Format and hit Enter.

The interface provides highly detailed key metrics:

  • Unique visitors: Filter actual visitors, removing noise from bots.
  • 404 Not Found: Immediately detect broken links or vulnerability scans from hackers.
  • Visitor Hostnames & IPs: Identify specific IPs hitting the server with unusual frequency.

Quick Tip: Press s to sort data or use the number keys 1-9 to quickly jump between different statistical tables.

Turning GoAccess into a Professional Web Dashboard

While the terminal view is cool, a web interface is unbeatable for reporting or continuous monitoring. GoAccess includes a built-in WebSocket server to push the latest data to your browser without refreshing the page.

Use the following command to start rendering the dashboard:

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

Note: The -o parameter must point to the directory where your Nginx is serving web content. Now, just open http://your-server-ip/report.html. You’ll see charts updating in real-time as visitors hit the site.

Real-world Tips to Prevent Server Crashes

GoAccess is extremely lightweight (typically using 30-50MB RAM), but if your log file is several gigabytes, the initial scan will take a while. Apply these three tips:

1. Only Process the Latest Logs

Instead of reading the entire backlog from last year, use tail to grab only the last 100,000 lines. This keeps the dashboard loading lightning fast:

tail -n 100000 /var/log/nginx/access.log | goaccess - -o /var/www/html/report.html --log-format=COMBINED --real-time-html

2. Run in the Background with Systemd

To keep the dashboard running after you exit the terminal, create a service file at /etc/systemd/system/goaccess.service. This is the standard approach for production environments.

3. Protect Your Dashboard with a Password

The report.html file contains sensitive information like visitor IPs and directory structures. Don’t leave it public. Use Nginx’s Basic Auth feature to protect it:

location /report.html {
    auth_basic "Please log in";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

Why Not Just Use Google Analytics?

People often ask me this. In reality, Google Analytics (GA) only sees what happens in the client’s browser. Hits from bots, 500 errors generated by code, or brute-force attacks on the system are completely invisible to GA.

GoAccess fills that gap. It sits on the boundary between a debugging tool and a performance monitoring system. It takes one minute to set up, but the value it provides when the server encounters issues is immense.

Conclusion

GoAccess is a sharp weapon for any system admin or DevOps engineer who prefers minimalism. It turns the dull task of reading Nginx logs into something visual and engaging. If you’re managing a small VPS, try installing it now to see what’s really happening behind the scenes of your website.

If you run into issues configuring WebSockets over HTTPS or customizing the log format, feel free to leave a comment below!

Share: