nginx commands

15 commands, each with a one-line explanation. Click a command to copy it, or its title for details.

Commands 15 shown

  • nginx -t

    Validate nginx.conf without reloading

  • nginx -s reload

    Gracefully reload config — zero connection drop

  • nginx -V 2>&1 | tr ' ' '\n' | grep module

    List all built-in and dynamic modules in the binary

    debug

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

    Stream IP, path, status code, and response size

    logs · monitoring

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

    Frequency of each HTTP status code in access log

    monitoring

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

    Most popular request paths from access log

    monitoring

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

    Top 10 client IPs hitting the server

    monitoring · security

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

    Limit to 10 req/s per IP with burst of 20 (add to http/server block)

    security

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

    Round-robin upstream with backup and keepalive connections

    network

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

    Compress text responses ≥1KB at level 6

    performance

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

    Custom JSON body for rate-limit or error responses

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

    Permanent redirect all HTTP traffic to HTTPS

    security

  • curl -s http://localhost/stub_status

    Built-in nginx status page: active, reading, writing, waiting

    monitoring

  • deny 192.168.1.0/24; deny 10.0.0.1; allow all;

    Block a subnet and specific IP in nginx location/server block

    security

  • location /ws/ { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; }

    WebSocket proxy with required Upgrade headers

    network