Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am looking to turn off logging in the Nginx access log file from specific requests from http user agents.

Basically from the Amazon ELB Health Check and our external (Pingdom) monitoring. Since these come every few seconds, makes testing hard to sort through the logs.

"GET / HTTP/1.1" 200 727 "-" "ELB-HealthChecker/1.0"
"GET /login HTTP/1.1" 200 7492 "-" "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)"

I was able to block logging for image files, but have not seen anything for incoming requests:

location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml|svg)$ {
        access_log        off;
        expires           30d;
}

Thanks in advance!


So I tried the recommendation from @Gnarfoz, but had some interesting side effects. While those two "Health Checks" were not logged, Pingdom started to recognize the server as DOWN even while it was up and running. That is interesting as the Load Balancer did not, which it would have dropped the node we were testing if it had.

I put the MAP section in the HTML block below my logs:

access_log /www/access.log;
error_log /www/error.log;

map $http_user_agent $ignore_ua {
            default                 0;
            "~Pingdom.*"            1;
            "ELB-HealthChecker/1.0" 1;
    }

And I put the IF statement in my server block, with the default location:

location / {
                try_files $uri $uri/ /index.php?$args;

                if ($ignore_ua) {
                       access_log off;
                }
        }

When I did this, Pingdom started to generate 404 errors in the Error Log file:

2012/08/03 17:10:33 [error] 6250#0: *164 open() "/www/public_html/login" failed (2: No such file or directory), client: 10.xx.xx.xx, server: xxx.com, request: "GET /login HTTP/1.1", host: "xxx.com"
2012/08/03 17:11:32 [error] 6250#0: *240 open() "/www/public_html/login" failed (2: No such file or directory), client: 10.xx.xx.xx, server: xxx.com, request: "GET /login HTTP/1.1", host: "xxx.com"
share|improve this question
    
That's the user-agent by the way, not the referrer. –  Gnarfoz Aug 3 '12 at 15:09
    
Thanks, wasn't sure I was using the proper terminology with that –  briannyc Aug 3 '12 at 16:52
    
Ah, my bad. While I haven't had any coffee yet, I think you need to actually return something in that location block, too. So maybe a simple return 200; after the access_log off; might do the trick. (Non-) Inheritance of nginx configuration directives still is not entirely clear to me at all times... –  Gnarfoz Aug 6 '12 at 8:06
    
You are correct, adding return 200; worked perfectly! Thank you for your help. –  briannyc Aug 6 '12 at 19:56
    
Good to hear that works. I've updated my answer accordingly. –  Gnarfoz Aug 7 '12 at 8:21

1 Answer 1

up vote 1 down vote accepted

Try this:

map $http_user_agent $ignore_ua {
    default                 0;
    "~Pingdom.*"            1;
    "ELB-HealthChecker/1.0" 1;
}

location / {
    if ($ignore_ua) {
        access_log off;
        return 200;
    }
}

The if part would probably need to be integrated into your appropriate location block.

Relevant nginx documentation: map, if, access_log

share|improve this answer
    
Tried your recommendation with some interesting side effects. I might have put the IF statement in the wrong location. Will keep playing with it. –  briannyc Aug 3 '12 at 17:29
    
This did not work for me. –  Mauvis Ledford Sep 9 at 23:30
    
Didn't work for me either, but I think this is on the right track for how to handle this. –  xxdesmus Sep 12 at 16:14
    
Tiny update -- map goes outside of the server block by the way, just in case that helps folks. This does work for me though. –  xxdesmus Sep 12 at 16:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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