Nginx access logs contain a wealth of information, but directly reading them can be a daunting task for most people. Fortunately, we have powerful tools like GoAccess that help us easily analyze and visualize Nginx access logs.
Tool Installation
Debian-based Systems (e.g., Ubuntu)
You can install GoAccess with the following commands:
sudo apt-get update
sudo apt-get install goaccess
Red Hat-based Systems (e.g., CentOS)
Install with:
sudo yum -y install goaccess
Installing from Source Code
If you wish to install GoAccess from source, follow these steps. First, download the source package:
wget https://tar.goaccess.io/goaccess-1.4.tar.gz
Extract and compile:
tar -xzvf goaccess-1.4.tar.gz
cd goaccess-1.4/
./configure --enable-geoip --enable-utf8
make && sudo make install
Tool Configuration
GoAccess needs configuration to correctly parse Nginx access logs. The config file is usually at /etc/goaccess/goaccess.conf
.
For the default Nginx log format, you can simply use the --log-format=COMBINED
parameter.
If you've set a custom log format in your Nginx configuration, specify the corresponding log format in the GoAccess config file. For example:
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
You also need to define the date and time formats so GoAccess can parse timestamps correctly, e.g.:
date-format %d/%b/%Y
time-format %H:%M:%S
Log Analysis
Run GoAccess in the terminal to enter its interactive interface, which displays log analysis results.
For example:
goaccess /var/log/nginx/access.log --log-format=COMBINED
GoAccess can also generate an HTML report, viewable in your browser. The following command will create a report.html
file with comprehensive statistics and charts:
goaccess /var/log/nginx/access.log -o report.html --log-format=COMBINED
To enable real-time monitoring and generate a dynamically updating HTML report, use:
--real-time-html --daemonize
Sample full command:
goaccess /var/log/nginx/access.log -o /var/www/html/report.html --log-format=COMBINED --real-time-html --daemonize
Understanding the Analysis Results
GoAccess provides a wealth of statistics and charts, helping you comprehensively understand your website’s visitors, including:
Overview
Metric | Description |
---|---|
Total Hits | Shows the total website visits |
Unique Visitors | Counts unique IP addresses |
Data Transferred | Total data sent (MB or GB) |
Visitor Information
Metric | Description |
---|---|
IP Rankings | IP addresses by visit count |
Browsers & OS | Visitor browser and OS details |
Request Information
Metric | Description |
---|---|
Methods | Number of different HTTP methods |
Status Codes | HTTP status (200 = OK, 404 = Not Found, etc.) |
URL Rankings | Most accessed URLs |
Performance Analysis
Metric | Description |
---|---|
Time Distribution | Requests per time period |
Slowest Requests | Requests with longest response times |
Advanced Usage
Besides basic analytics, GoAccess supports advanced features such as pipes and filters.
For real-time analysis, run:
tail -f /var/log/nginx/access.log | goaccess -p /etc/goaccess/goaccess.conf
To analyze and merge multiple log files:
goaccess -p /etc/goaccess/goaccess.conf access.log.1 access.log.2
Let me know if you need more explanation or have any other questions!
Top comments (0)