Welcome! Log In Create A New Profile

Advanced

Conditional Logging

Posted by cjraven 
Conditional Logging
April 06, 2012 01:56PM
Greetings everyone,

I'm putting nginx in front of Apache to serve a small number of WordPress sites.

In Apache I do a fair amount of conditional logging to keep logfile cruft to an absolute minimum. Wondering about how to go about the same in nginx

Here's the Apache conditional logging stanzas;

## flag robots.txt requests (if only bots would honor 'em)
SetEnvIf Request_URI "^/robots\.txt$" robots=1

## flag image requests
SetEnvIf Request_URI \.gif image-request=1
SetEnvIf Request_URI \.jpg image-request=1

# think this was covered in http://forum.nginx.org/read.php?2,212305,212306#msg-212306 but where the "don't log" directive is, can't figure out

## flag whitelisted IP's - IMPORTANT!!
SetEnvIf Remote_Addr "1\.2\.3\.4" local=1
SetEnvIf Remote_Addr "5\.6\.7\.8" local=1
## etc

# Get rid of wp-cron loggng
SetEnvIf Request_URI ^/wp-cron.php$ uri=1

# sum it all up
## set do_not_log if any of the above flags are set
SetEnvIf robots 1 do_not_log=1
SetEnvIf image-request 1 do_not_log=1
SetEnvIf local 1 do_not_log=1
SetEnvIf uri 1 do_not_log=1

# write or don't write as the case may be
CustomLog /home/mcmandrel/public_html/logs/access.log combined env=!do_not_log

All suggestions and guidance would be most welcome!

Regards & TIA,
-Colin
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 238
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready