当前位置: > Linux服务器 > apache >

apache日志只记录Baidu蜘蛛的记录

时间:2015-01-10 13:03来源:linux.it.net.cn 作者:IT
Apache默认的日志记录方式:
LogFormat "%h %l %u %t \"%r\" %>s %b" common
记录到的如下:
61.135.168.14 - - [22/Oct/2008:22:13:11 +0800] "GET / HTTP/1.1" 200 8427
 
Apache还有个较复杂的combined的日志记录方式,如下:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
其记录到的类似:
61.135.168.14 - - [22/Oct/2008:22:13:31 +0800] "GET / HTTP/1.1" 200 8427 "-" "Baiduspider+(+http://www.baidu.com/search/spider.htm)"
 
为了能更方便的了解Baidu蜘蛛来访的情况,索性单独写了个只记录Baidu蜘蛛来访记录。common中的%l和%u好像都记录不到东西的,所以也去掉。
 
SetEnvIfNoCase User-Agent Baiduspider baidu_robot
LogFormat "%h %t \"%r\" %>s %b" robot
CustomLog "|/usr/local/apache2.2.0/bin/rotatelogs /usr/local/apache2.2.0/logs/baidu_%Y%m%d.txt 86400 480" robot env=baidu_robot
 
这样在logs目录下,就会每天产生baidu_年月日.txt的日志了,每条的记录和下面的类似:
61.135.168.14 [22/Oct/2008:22:21:26 +0800] "GET / HTTP/1.1" 200 8427
(责任编辑:IT)
------分隔线----------------------------