SetEnvIf: Apache httpd log filter
Blogs20142014-02-12
SetEnvIf: Apache httpd log filter
My dedicated server’s (in godday.com) log files (error.log, access.log) are frequently accessed by google Googlebot and some engine spiders or from certain IPs, thus generate duplicated, useless log messages.
I have to filter these kind of messaghe to make logfile’s size increase not so quickly. I use ’SetEnvIf’ in httpd.conf to customize the log output to prevent such logging requests for both error.log and access.log.
Here is a detailed introduction of ’SetEnvIf‘: How To Tell Apache To Not Log Certain Requests In Its Access Log?
The following are some ’SetEnvIf’ examples to filter certain IPs:
- To prevent all requests made with a certain browser, e.g. Internet Explorer, from getting logged:
SetEnvIf User_Agent “(MSIE)” dontlog
- To not log requests from any client whose hostname ends in bla.example.com, use:
SetEnvIf Remote_Host “bla.example.com$” dontlog
- To not log requests from any client whose hostname begins with example, use:
SetEnvIf Remote_Host “^example” dontlog
- To not log requests from a certain IP address, use something like:
SetEnvIf Remote_Addr “192.168.0.154” dontlog
- If you don’t want requests of your robots.txt to get logged, use:
SetEnvIf Request_URI ”^/robots.txt$” dontlog
- Apart from SetEnvIf, which is case-sensitive, you can use SetEnvIfNoCase which is case-insensitive.
For example, in order not to log certain search engine spiders, you could use:
SetEnvIFNoCase User-Agent "Slurp/cat" dontlog
SetEnvIFNoCase User-Agent "Ask Jeeves/Teoma" dontlog
SetEnvIFNoCase User-Agent "Googlebot" dontlog
SetEnvIFNoCase Remote_Host "fastsearch.net$" dontlog- Or to not log certain file extensions, use something like this:
SetEnvIfNoCase Request_URI “.(gif)|(jpg)|(png)|(css)|(js)|(ico)|(eot)$” dontlog
- To not log certain referrals (e.g. from your own domain), use something like:
SetEnvIfNoCase Referer “www.mydomain.com” dontlog
