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

没用的蜘蛛都删除,有用的才保留