Nginx

<< Back to wiki homepage

Table of contents:

Config

Same response for multiple blocks

    error_page 418 = @health_check;
    location ~ ^/(health|check)$ {
        return 418;
    }
    location @health_check {
        proxy_pass       http://127.0.0.1:9999;

        proxy_set_header Connection "";

        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        add_header X-Something-HealthCheck 'OK';
        add_header  X-Something-Web  2;
        access_log /var/log/nginx/hc_access.log;
    }

Logs

Show last/most active visitors

tail -1000 /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -k1n