Show top IPs by request count

Top 10 client IPs that send the most requests

awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -10

tool
nginx15 commands
tags
nginxmonitoringsecurity

More nginx commands

  • limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; limit_req zone=api burst=20 nodelay;

    Allow 10 req/s per IP with a burst of 20; limit_req_zone goes in http, limit_req in server or location

  • upstream backend { server 10.0.0.1:8080; server 10.0.0.2:8080 backup; keepalive 32; }

    Upstream with keepalive connections and a backup server that gets traffic only when the main one is down

  • gzip on; gzip_types text/plain text/css application/json application/javascript; gzip_min_length 1024; gzip_comp_level 6;

    Compress text responses of 1 KB and larger at level 6

  • error_page 429 /429.json; location = /429.json { default_type application/json; return 429 '{"error":"rate_limited"}'; }

    Custom JSON body for 429 and other error responses

  • server { listen 80; return 301 https://$host$request_uri; }

    Send all HTTP traffic to HTTPS with a permanent 301 redirect

all 15 nginx commands