12

I'm running nginx behind haproxy (running on the same server). I've configured haproxy to use a simple html file on nginx to verify the service is up, since I don't have/want a valid "/" URL on this host. Nginx doesn't support the OPTIONS request type (as far as I know) which is the default that haproxy uses, so I've changed it to a GET.

Since I have access logs turned on in nginx, I'm getting all these uptime poll requests in my access log. Is there a way that I can configure nginx to ignore certain requests, and skip logging them?

Here's the haproxy backend:

backend static_http
        option  httpchk GET /test.html
        option  redispatch
        balance roundrobin
        #fullconn 1000
        server  w1_static www1:81 check port 81 inter 2000

And Here's what I see in the nginx logs:

127.0.0.1 - - [24/Jul/2009:19:28:22 +0000] "GET /test.html HTTP/1.0" 200 12 "-" "-"
127.0.0.1 - - [24/Jul/2009:19:28:24 +0000] "GET /test.html HTTP/1.0" 200 12 "-" "-"
127.0.0.1 - - [24/Jul/2009:19:28:26 +0000] "GET /test.html HTTP/1.0" 200 12 "-" "-"
127.0.0.1 - - [24/Jul/2009:19:28:28 +0000] "GET /test.html HTTP/1.0" 200 12 "-" "-"
127.0.0.1 - - [24/Jul/2009:19:28:30 +0000] "GET /test.html HTTP/1.0" 200 12 "-" "-"
Mark Henderson
  • 68,823
  • 31
  • 180
  • 259
Michael Marano
  • 151
  • 1
  • 1
  • 4

3 Answers3

16

You can now do this

http://nginx.org/en/docs/http/ngx_http_log_module.html

The if parameter (1.7.0) enables conditional logging. A request will not be logged if the condition evaluates to “0” or an empty string

map $request_uri $loggable {
  / 0;
  /healthcheck.html 0;
  default 1;
}

server {
...
  access_log /var/log/nginx/access.log combined if=$loggable;

}
KCD
  • 958
  • 3
  • 12
  • 24
8

Well, you could try having a specific location directive for this.

Something like

location /test.html {
  access_log off;
}

should work (untested)...

Jauder Ho
  • 5,507
  • 2
  • 19
  • 17
0

There's no built-in filtering that will do what you want.

There are a few tricks you might try though. These will all result in the data you're not interested in being logged to a different file, which you can nuke externally (remember to HUP nginx afterwards) as often as you feel is appropriate.

  • if haproxy is the only thing that requests /test.html, you can have a different access log per location block (unfortunately not for an if block inside a location block).

  • if other nodes request /test.html but all requests from 127.0.0.1 are haproxy, you could create a map based on $remote_addr that translates 127.0.0.1 to access_log.junk and everything else to access_log. Use the map variable in the name of the access log statement

Failing that, you've got the source, so hack what you need in.

James F
  • 6,689
  • 1
  • 26
  • 24