0

I thought this behaviour was quite weird, hence I am going to ask on here.

Take this location block;

location ~ /(wp-config.php|readme.html|licence.txt|license.txt|readme.txt) {
    access_log /var/log/nginx/blocked.log blocked;
    deny all;
}

It does not log anything to the log file, however if I remove the deny all; - it does. Same goes for return 403 etc

I want to log blocked requests.

nginx version: nginx/1.8.0

UPDATE

The cause of this appears to be when you define your own error pages. For eg:

http {  ..
    error_page          403          /error/403.html;
    error_page          404          /error/404.html;
.. }

Removing these lines allowed logging

1
  • Update #2 - moving the logging from this location block to the location block which defines the custom error page fixes the issue – anastymous Jun 18 '15 at 23:17
0

Things to check:

  1. Have you defined blocked?
  2. Or path to log file is correct?
  3. Check location order because wp-config.php most likely will match location ~ \.php$ or similar

It works for me with nginx: 1.7.11.1 Gryphon, though it is Windows enviroment.

Here is my setup:

http {
    ...
    log_format robots   '$remote_addr - $remote_user [$time_local] '
                        '$host "$request" $status $body_bytes_sent '
                        '"$http_referer" "$http_user_agent"';
    ...
    server {

    ...
        location ~/(robots.txt|readme.html) {
            access_log  logs/nginx-access-robots.log robots;
            deny all;
        }
    ...
    }

}
3
  • Yes. Logging works when I remove the Deny line. So everything with regarding to it being defined, correct path and location ordering is correct. I was running the test on license.txt – anastymous Jun 15 '15 at 9:53
  • I have copied exactly what you have above. Still stops logging as soon as I deny users. – anastymous Jun 15 '15 at 10:23
  • Do you have custom location for 403 page? i.e. location /403.html? Do you restart nginx on each config try? Can you share rest of config (you can change domain names to dummy ones etc.). Nginx is not like apache when htaccess can be changed on the fly. Or try this: create new server block with bare minimum to test this config Restart nginx to apply configuration. Try to access file in localhost:8080/robots.txt or as you have. – Pilskalns Jun 15 '15 at 11:51

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.