A command-line tool built with shell scripting to analyze Nginx access logs. This project processes a given access log file and outputs valuable statistics, including the top 5 IP addresses, requested paths, response status codes, and user agents.
The Nginx Log Analyser is designed to help you learn basic shell scripting while working with real-world data. By parsing the standard Nginx access log (in combined log format), the script extracts and summarizes key information about website traffic.
For more details and project inspiration, visit the Nginx Log Analyser project page.
- Top 5 IP Addresses: Identifies the IP addresses making the most requests.
- Top 5 Requested Paths: Lists the most frequently requested resources.
- Top 5 Response Status Codes: Summarizes HTTP status codes returned by the server.
- Top 5 User Agents: Provides insight into which browsers or bots are accessing your server.
- A Unix-like operating system (Linux, macOS, etc.)
- Basic knowledge of shell scripting and command-line usage.
- Tools:
awk,sort,uniq,head
-
Clone the Repository:
git clone https://github.com/kaalpanikh/nginx-log-analyser.git cd nginx-log-analyser -
Download the Log File (Optional):
If you want to test with a real log file, download the sample log file:
curl -o access.log "https://gist.githubusercontent.com/kamranahmedse/e66c3b9ea89a1a030d3b739eeeef22d0/raw/77fb3ac837a73c4f0206e78a236d885590b7ae35/nginx-access.log" -
Make the Script Executable:
chmod +x nginx_log_analyser.sh
Run the script by providing the path to your access log file:
./nginx_log_analyser.sh access.logThe output will display the following statistics:
- Top 5 IP addresses
- Top 5 requested paths
- Top 5 response status codes
- Top 5 user agents
Once you have the basic functionality working, consider these enhancements:
- Add error handling for missing or malformed log files.
- Format output as CSV or JSON for easier integration with other tools.
- Extend the script to analyze additional data such as referrers or daily traffic.
- Experiment with alternative tools like
greporsedfor parsing.
Contributions are welcome! Feel free to fork the repository and submit pull requests. For major changes, please open an issue first to discuss your ideas.
This project is licensed under the MIT License. See the LICENSE file for details.
Happy scripting and analyzing!