Tail the access log with key fields

Stream client IP, path, status code and response size

tail -f /var/log/nginx/access.log | awk '{print $1, $7, $9, $10}'

tool
nginx15 commands
tags
nginxlogsmonitoring

More nginx commands

  • awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn

    How many times each HTTP status code appears in the access log

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

    Most requested paths from the access log

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

    Top 10 client IPs that send the most requests

  • 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

all 15 nginx commands