分析nginx日志的时候,比较头疼的是有许多蜘蛛爬虫的痕迹。
鉴于多数蜘蛛爬虫都是叫xx-bot或者xx-spider,下面的方法可以给爬虫单独写日志:
location / { if ($http_user_agent ~* "bot|spider") { access_log /var/log/nginx/spider.access.log; } }
或者干脆不写日志
location / { if ($http_user_agent ~* "bot|spider") { access_log off; } }
本文出自 “Purple_Grape的博客” 博客,请务必保留此出处http://purplegrape.blog.51cto.com/1330104/1377365
原文:http://purplegrape.blog.51cto.com/1330104/1377365