分析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;
   }
}