Enabling Real-Time HTML Reports with GoAccess & NGINX

If you manage a web server, you know that access to real-time data can be a game-changer. It’s beneficial to see exactly how your server is performing at any given moment, how traffic is flowing, and how users are interacting with your site. That’s where the open-source log analyzer, GoAccess, steps in. Paired with the powerful NGINX reverse proxy, it provides real-time web log analysis straight to your browser. In this article, we’ll guide you through setting up GoAccess with NGINX for real-time HTML reports.

Introduction to GoAccess

GoAccess is a lightweight, open-source log analyzer that provides valuable insights into your web traffic by processing web server logs. One of the key features of GoAccess is its ability to generate real-time HTML reports, giving you access to real-time web traffic data in a visual, easy-to-understand format.

Setting Up GoAccess

To get started with GoAccess, you will need to install it on your server. You can typically do this through your package manager. For example, on a Debian-based system, you can use apt:

yum install goaccess

Once installed, GoAccess is typically run from the command line and can parse and analyze your server logs. The command to run GoAccess against your server logs might look like this:

goaccess /var/log/nginx/access.log --log-format=COMBINED

This command tells GoAccess to analyze the NGINX access log found at /var/log/nginx/access.log.

Configuring GoAccess for Real-Time Reports

Real-time reporting with GoAccess relies on WebSockets to push updates from the server to your web browser. To enable this feature, GoAccess needs to be configured to output an HTML report and to keep the process running for real-time updates.

A simple GoAccess command for real-time HTML reports might look like this:

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

In addition to the --real-time-html option that enables real-time updates, the -o option specifies where the HTML report will be output.

To run GoAccess as a service, you can create a systemd unit file for GoAccess:

[Unit]
Description=GoAccess Web Log Analyzer
After=network.target

[Service]
ExecStart=/usr/bin/goaccess /var/log/nginx/access.log --log-format=COMBINED --real-time-html -o /var/www/html/report.html

[Install]
WantedBy=multi-user.target

Save this file as /etc/systemd/system/goaccess.service and then start and enable the service with:

systemctl start goaccess
systemctl enable goaccess

Configuring NGINX as a Reverse Proxy for GoAccess

With GoAccess running and generating real-time HTML reports, you need a way to securely serve these reports over the internet. This is where NGINX steps in. NGINX can act as a reverse proxy, serving the GoAccess HTML report while also providing features such as HTTPS encryption.

Here’s a basic example of how you might configure an NGINX server block to serve GoAccess reports:

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass https://localhost:7890;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
    }
}

In this configuration, proxy_pass points to the GoAccess real-time HTML report, and the Upgrade and Connection headers are set to allow for the WebSocket connection needed for real-time updates.

Wrap Up

Setting up GoAccess for real-time HTML reports provides a powerful tool for monitoring your web server. When coupled with NGINX as a reverse proxy, you can securely serve these reports over the internet, providing a window into your server’s activity at any moment. By understanding the role of the Upgrade header and how to configure GoAccess and NGINX, you can take full advantage of real-time web log analysis.

Scroll to Top