William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

SetEnvIf: Apache httpd log filter

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: