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: - - [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?


  • 4
    There's no rewrite directive in that location block, so it can't be being used. Please provide the rest of your configuration. – mgorven Mar 15 '13 at 20:00

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!

| improve this answer | |

You can exclude 3xx status from being log using map like

map $status $log {
    default     1;
    ~^[^3]      0;

Then change access_log to :

access_log  /var/log/nginx/access.log combined if=$log;
| improve this answer | |
  • or use it more simple like map $status $log {default 1;301 0;302 0;} – a55 Oct 17 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.