0

I am trying to make nginx's access log conditional using an if statement but its not working.

This is the relevant code from the configuration file.

map $uri $log_access {

    /.lb-check 0;

    default 1;
}

server {
    ...

    access_log /var/log/nginx/access.log combined if=$log_access;

    ...
}

I don't want certain requests to be logged, in this instance its a request made by the load balancer to the url /.lb-check

Unfortunately this configuration isn't working

I have also tried doing the following and that doesn't work either.

location = /.lb-check { access_log off; }

Does anyone know why these methods aren't working?

ArthurGuy
  • 1,459
  • 4
  • 13
  • 25
  • 1
    Your `access_log off` should absolutely work, so it more sounds like perhaps NGINX isn't reloading when you're applying that change. Ensure your configuration is valid with `nginx -t`. You may want to consider doing `location /.lb-check` instead fo `location = /.lb-check` in case you are also receiving requests for "/.lb-check/" which won't be covered – Joshua DeWald May 16 '18 at 15:54

1 Answers1

1

This turned out to be a configuration issue with an internal build system but after solving that I ended up using the map method but with the $request_uri parameter

map $request_uri $log_access {

  /.lb-check 0;
  default 1;

}

location = /.lb-check didn't work as it overrode the handling of that request meaning nothing was defined to serve the request (should have gone to a php handler).

ArthurGuy
  • 1,459
  • 4
  • 13
  • 25