8000 GitHub - EODavis/nginx-log-analyser · GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Nginx Log Analyser

A simple shell script to analyze an Nginx access log file from the command line.

This project extracts and displays:

  • Top 5 IP addresses with the most requests
  • Top 5 most requested paths
  • Top 5 response status codes
  • Top 5 user agents

Project URL: https://roadmap.sh/projects/nginx-log-analyser

Files

  • nginx-log-analyser.sh — main shell script
  • nginx-access.log — sample Nginx access log file

Requirements

  • Bash shell

  • Standard Unix command-line tools:

    • awk
    • sort
    • uniq
    • head
    • sed

How to Run

  1. Clone the repository:

    git clone <your-repository-url>
    cd nginx-log-analyser
  2. Make the script executable:

    chmod +x nginx-log-analyser.sh
  3. Run the script:

    ./nginx-log-analyser.sh nginx-access.log

Example Output

Top 5 IP addresses with the most requests:
45.76.135.253 - 1000 requests
142.93.143.8 - 600 requests

Top 5 most requested paths:
/api/v1/users - 1000 requests
/api/v1/products - 600 requests

Top 5 response status codes:
200 - 1000 requests
404 - 600 requests

Top 5 user agents:
Mozilla/5.0 (...) - 400 requests
curl/7.68.0 - 200 requests

Approach

The script uses shell utilities to parse the Nginx access log:

  • awk to extract specific fields such as IP addresses, request paths, status codes, and user agents
  • sort and uniq -c to count repeated values
  • sort -nr to rank values by frequency
  • head -5 to display the top 5 results

Notes

  • The script expects the log file path as a command-line argument.
  • If the file does not exist, the script exits with an error message.

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0