当前位置: > Linux服务器 > nginx >

Nginx 用 User-Agrent 禁止部分访问

时间:2015-06-28 20:39来源:linux.it.net.cn 作者:IT
为节省流量,禁止部分流氓爬虫或不重要的爬虫。nginx 用 if 和 $http_user_agent可以禁止部分访问。

如:

location / { 
    root   /home/www/; 

    if ($http_user_agent ~* "qihoobot") { 
        return 403; 
    } 
    #... 
}  然后重启 nginx

nginx -s reload可以用 curl 测试一下

curl -I -A "qihoobot" localhost看到返回 403 就正常了

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容