您的位置:首页 > 运维架构 > Nginx

Nginx禁止指定user_agent

2017-06-14 17:52 323 查看
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
没用的蜘蛛都删除,有用的才保留
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  user Nginx 禁止指定