GoAccess is a real-time web log analyzer and interactive viewer that runs in a terminal on Unix-like systems or through your browser. It provides fast and valuable HTTP statistics for system administrators, offering detailed reports on metrics like visitor locations, operating systems, bandwidth usage, and more.
Nginx Admin (also referred to as Nginx Manager) is a tool for managing Nginx servers. It simplifies the configuration and monitoring of Nginx, making it easier to handle web traffic, manage server resources, and ensure high performance and availability of web applications.
In this guide, we will cover how to install and run GoAccess with either Nginx or Apache using Docker. This setup will allow you to monitor your web server logs in real-time through a web interface, providing valuable insights into your web traffic.
Before we start, ensure you have the following:
You can use either Nginx or Apache to serve your web traffic. Follow the appropriate instructions based on your choice.
If you choose Nginx, follow these steps:
sudo apt update
sudo apt install nginx
Ensure the access_log
directive is set correctly in your Nginx configuration file (usually found in /etc/nginx/nginx.conf
or /etc/nginx/sites-available/default
):
access_log /var/log/nginx/access.log;
Ensure the access_log
directive is set correctly in your Nginx configuration file (usually found in /etc/nginx/nginx.conf
or /etc/nginx/sites-available/default
):
sudo systemctl restart nginx
If you choose Apache, follow these steps:
Install Apache:
sudo apt update
sudo apt install apache2
Ensure the LogFormat
and CustomLog
directives are set correctly in your Apache configuration file (usually found in /etc/apache2/apache2.conf
or /etc/apache2/sites-available/000-default.conf
):
LogFormat "%h %l %u %t \"%r\" %>s %b" combined
CustomLog /var/log/apache2/access.log combined
sudo systemctl restart apache2
If you haven't installed Docker and Docker Compose yet, you can do so with the following commands:
Install Docker:
sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install -y docker-ce
Install Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
Create a new directory for your project and navigate into it:
mkdir goaccess-docker
cd goaccess-docker
Create a docker-compose.yml
file with the following content:
version: '3'
services:
webserver:
image: nginx:latest # Replace with 'httpd:latest' for Apache
ports:
- "80:80"
volumes:
- ./webserver.conf:/etc/nginx/nginx.conf # Replace with 'apache.conf' for Apache
- ./log:/var/log/nginx # Replace with '/var/log/apache2' for Apache
goaccess:
image: allinurl/goaccess
volumes:
- ./log:/usr/local/nginx/logs # Replace with '/usr/local/apache2/logs' for Apache
- ./goaccess:/goaccess
command: goaccess /usr/local/nginx/logs/access.log -o /goaccess/report.html --log-format=COMBINED --real-time-html
ports:
- "7880:7880"
In the same directory, create a configuration file for your chosen web server.
Create a webserver.conf
file with the following content:
events {}
http {
log_format combined '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log combined;
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
}
Create an apache.conf
file with the following content:
ServerRoot "/usr/local/apache2"
Listen 80
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
User daemon
Group daemon
ServerAdmin you@example.com
ServerName localhost
DocumentRoot "/usr/local/apache2/htdocs"
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory "/usr/local/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
LogFormat "%h %l %u %t \"%r\" %>s %b" combined
CustomLog /var/log/apache2/access.log combined
ErrorLog /var/log/apache2/error.log
LogLevel warn
Create the necessary directories for logs and GoAccess data:
mkdir log
mkdir goaccess
Now, start your Docker containers:
docker-compose up -d
This command will start both the web server and GoAccess containers in the background. The web server will serve your web traffic and log the access logs to the log
directory. GoAccess will read these logs and generate a real-time HTML report.
Open your browser and navigate to http://your_server_ip:7880
to see the GoAccess real-time report.
You've now successfully set up GoAccess with either Nginx or Apache using Docker. This setup allows you to monitor your web server logs in real-time through a web interface, providing valuable insights into your web traffic. Adjust configurations and explore further customization to suit your needs.
Comments