Nginx禁止指定user_agent
[root@LHQ ~]# cd /usr/local/nginx/conf/vhosts
[root@LHQ vhosts]# vim test.conf
使用 user_agent 控制客戶端訪問
location /
{
if ($http_user_agent ~* 'bingbot/2.0|MJ12bot/v1.4.2|Spider/3.0|YoudaoBot|Tomato|Gecko/20100315')(匹配波浪號後面的字符,直接顯示403;~*:組合一起使用,意思是不區分大小寫)
{
return 403;
}
}
使用curl測試:
[root@LHQ vhosts]# curl -A "wsefdfewfefe.ferwfe" -x192.168.1.254:80 www.test.com/forum.php -I
沒用的蜘蛛都刪除,有用的才保留