A simple yet powerful bash script to analyze Nginx access logs and provide insights about traffic patterns, response codes, and most requested paths.
The script provides three main types of analysis:
- Top IP addresses making the most requests
- Most frequent HTTP response status codes
- Most requested URL paths
- Bash shell environment
- Nginx access logs (named
nginx-logs.txt
in the same directory as the script) - Basic Unix tools:
awk
,sort
,uniq
,grep
- Clone or download the repository
- Make the script executable:
chmod +x nginx-analyzer.sh
- Ensure your Nginx access log file is named
nginx-logs.txt
and is in the same directory as the script - Run the script:
./nginx-analyzer.sh
- When prompted, enter the number of top results you want to see
The script generates three sections of output:
Shows the IP addresses that made the most requests:
IP - [IP_ADDRESS] - [NUMBER] times
Displays the most frequent HTTP response status codes:
Code - [STATUS_CODE] - [NUMBER] requests
Lists the most frequently requested URL paths:
Path - [URL_PATH] - [NUMBER] requests
$ ./nginx-analyzer.sh
Show Top: 3
----- Top 3 IPs with the most requests -----
IP - 192.168.1.100 - 150 times
IP - 10.0.0.1 - 120 times
IP - 172.16.0.50 - 90 times
----- Top 3 response status codes -----
Code - 200 - 400 requests
Code - 404 - 50 requests
Code - 500 - 10 requests
----- Top 3 most requested paths -----
Path - /index.html - 200 requests
Path - /api/users - 150 requests
Path - /images/logo.png - 100 requests
- The script assumes the Nginx log file follows the default Nginx log format
- The log file must be named
nginx-logs.txt
and be in the same directory as the script - Make sure you have the necessary permissions to read the log file