GoAccess is a powerful web log analyzer that generates real-time web traffic statistics.
In this article, I'll show you how to set up GoAccess on Ubuntu/Linux and access the report over a domain/sub-domain. Whether you're using Apache, Nginx, or any other web server, you can use the same approach (I've used Caddy in this tutorial). So, let's get started!
Prerequisites
Before we start, make sure you have the following prerequisites installed:
- Docker
- Docker Compose
- Caddy (or any other web server you prefer)
Step 1: Create directories for GoAccess
First, create/ensure two directories on your Ubuntu/Linux machine to store the log files and the HTML report generated by GoAccess. Run the following commands:
#sudo mkdir /var/log/caddy - caddy server will create the dir.
sudo mkdir /var/www/goaccess
Step 2: Create a Docker Compose file
Next, create a Docker Compose file named "docker-compose.yml" in any directory of your choice with the following content:
version: '3'
services:
goaccess:
image: allinurl/goaccess:latest
volumes:
- "/var/log/caddy:/var/log/caddy:ro"
- "/var/www/goaccess:/var/www/goaccess:rw"
ports:
- "7890:7890"
command: "/var/log/caddy/access.log --log-format=CADDY -o /var/www/goaccess/index.html --real-time-html --ws-url=wss://sub.domain.com:443/ws --port=7890"
This Docker Compose file defines a service named "goaccess" using the official GoAccess Docker image. The "volumes" section sets up two bind mounts that map the directories we created in step 1 to the corresponding directories inside the container. The first mount is read-only and maps the Caddy access logs to the "/var/log/caddy" directory inside the container. The second mount is read-write and maps the directory where we want to generate the HTML report to the "/var/www/goaccess" directory inside the container.
The "ports" section maps port 7890 on the host to port 7890 inside the container. This allows us to access the GoAccess report using a web browser.
The "command" section specifies the command to run when the container starts(More). In this case, we're telling GoAccess to analyze the Caddy access logs using the CADDY log format, generate an HTML report in real-time, and serve it over a WebSocket connection to the specified URL.
Step 3: Create a Caddy server block
Now, create a Caddy server block in the Caddyfile that proxies WebSocket traffic from the specified path "/ws" to the GoAccess container running on localhost at port 7890. Run the following command to open the Caddyfile:
sudo nano /etc/caddy/Caddyfile
Then add the following server block:
sub.domain.com {
root * /var/www/goaccess
# Enable the static file server.
file_server
reverse_proxy /ws localhost:7890
}
This server block specifies how to serve traffic to the domain/sub-domain "sub.domain.com" and how to proxy WebSocket traffic to the GoAccess container running on localhost at port 7890.
Step 4: Start the GoAccess container
Now we can start the GoAccess container using Docker Compose. Run the following command:
sudo docker-compose up -d
This command will start the GoAccess container in detached mode, which means it will run in the background.
Step 5: Access the GoAccess report
Finally, you can access the GoAccess report by visiting the domain/sub-domain "sub.domain.com" on the configured port 7890. You should see the real-time web traffic statistics in your browser.
Conclusion
Congratulations, you have successfully set up GoAccess in Ubuntu/Linux with Docker and real-time access over domain/sub-domain! With this setup, you can monitor and analyze the web traffic to your website in real-time and make informed decisions to improve its performance.
Top comments (0)