有些 bot 很討厭,掃描速度快,而且感覺在猜測網站內容,打出很多 HTTP 404:
$ grep bot access.log | awk '{print $NF}' |sort | uniq -c | sort -n | tail
298 +http://napoveda.seznam.cz/en/seznambot-intro/)"
525 +http://www.brandwatch.net)"
599 +http://yandex.com/bots)"
1005 bot@linguee.com)"
1233 Safari/537.36"
1421 +http://www.bing.com/bingbot.htm)"
5335 +https://seostar.co/robot/)"
48104 +http://www.semrush.com/bot.html)"
81520 +http://www.google.com/bot.html)"
93660 +http://ahrefs.com/robot/)"
參考了別人 $http_user_agent 的處理方法:
if ($http_user_agent ~* (AhrefsBot|SemrushBot)) {
return 444;
}
另外要注意的是:
~*:這個不分大小寫 (case insensitive)~:這個會區分大小寫
ps. 一般來說可以參考 HTTP status code 給 HTTP 403、444 等狀態碼,我是不爽所以給 HTTP 418