How can I stop nginx logging Amazon Route 53 Health Check requests?

Right now, my AWS health check hits my server pretty tirelessly:

... 54.228.16.40 - - [14/Jan/2014:10:17:22 +0000] "GET / HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" 54.248.220.40 - - [14/Jan/2014:10:17:24 +0000] "GET / HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" 54.232.40.110 - - [14/Jan/2014:10:17:25 +0000] "GET / HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" 54.241.32.78 - - [14/Jan/2014:10:17:26 +0000] "GET / HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" 54.245.168.46 - - [14/Jan/2014:10:17:28 +0000] "GET / HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" 54.251.31.174 - - [14/Jan/2014:10:17:28 +0000] "GET / HTTP/1.1" 301 178 "-" "Amazon Route 53 Health Check Service" ... 

And I would like to configure NginX so as not to register requests using the "Amazon Route 53 Health Check Service" user agent.

My current attempt is as follows:

 # default server for forwarding all requests over to main www domain server { listen 80 default_server; server_name _; return 301 $scheme://www.example.com$request_uri; } # server configured to catch aws health check requests server { listen 80; server_name 12.345.67.89; location / { if ( $http_user_agent ~* 'Amazon Route 53 Health Check Service' ) { access_log off; return 200 'Service OK'; } } } # actual application server server { listen 80; server_name www.example.com; location / { ... } } 

This looks good to me, and in fact, when I have CURL the same address that is set for health check:

 curl --user-agent "Amazon Route 53 Health Check Service" http://12.345.67.89:80/ 

I get what I expect:

 Service OK 

And my request does not end in the logs.

However, my logs are still loaded with these requests when they come from the actual AWS health check.

Any ideas on where I'm doing it wrong?

thanks

+6
source share
2 answers

So, it turns out that my health check was configured on example.com and not on the ip address: my bad.

For the record, I discovered this by adding the $host variable to my log formats (see end of line):

 log_format debug_format '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for" host:"$host"'; access_log /var/log/nginx/access.log debug_format; 

Greetings anyway

+1
source

We can display the user agent variable set by NGINX and set the boolean values ​​that will be used to determine the path and format of the access log. Check the nginx block below for reference.

 map $http_user_agent $log_ua { ~Pingdom 0; ~Amazon-Route53 0; ~SomeOtherUA 0; default 1; } server { ... access_log /var/log/nginx/access.log main combined if=$log_ua; } 
0
source

All Articles