Nginx – access_log off for a 301 or a 302

haproxyloggingnginx

I am using haproxy and nginx. Haproxy has sthis option to check health of my backends:

option httpchk HEAD /lol.txt HTTP/1.0

All works fine, but I do not want to log this health check

So in my nginx configuration I add:

    location /lol.txt {
    access_log off;
    }

The problem is, this location returns a 301, so I got these logs again and again:

 10.1.29.1 - - [15/Mar/2013:06:51:36 +0100] "HEAD /lol.txt HTTP/1.0" 301 0 "-" "-"

Have you some idea to have the access_log off working?

Regards.

Best Answer

You probably have some other location that handles the request, and your access_log doesn't apply, or maybe it gets overwritten by another access_log directive.

Try the following if you want to disable passing these requests to the backend:

location = /lol.txt {
    access_log off;
    return 'It works!' 200;
}

Or, alternatively, if you still must pass the request to be backend:

if ($request_uri = /lol.txt) {
    access_log off;
}

It might also help to try to make sure that these access_log off appear after any other access_log directives, e.g. see if moving it around makes a difference.

Hope it helps, and please report what worked!