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

nginx的高级配置(5)——访问控制

2015-12-02 14:14 656 查看
限制只让某个ip访问
allow 219.232.244.234;
deny all;

禁止某个IP或者IP段访问站点的设置方法

首先建立下面的配置文件放在nginx的conf目录下面,命名为deny.ip
cat deny.ip
deny 192.168.1.11;
deny 192.168.1.123;
deny 10.0.1.0/24;

在nginx的配置文件nginx.conf中加入:
include deny.ip;

重启一下nginx的服务:/usr/local/nginx/sbin/nginx reload 就可以生效了。

deny.ip 的格式中也可以用deny all;
如果想实现这样的应用,除了几个IP外,其他全部拒绝,
那需要在deny.ip 中这样写
allow 1.1.1.1;
allow 1.1.1.2;
deny all;

有时候会根据目录来限制php解析:
location ~ .*(diy|template|attachments|forumdata|attachment|image)/.*\.php$
{
deny all;
}

使用 user_agent 控制客户端访问
location /
{
if ($http_user_agent ~ 'bingbot/2.0|MJ12bot/v1.4.2|Spider/3.0|YoudaoBot|Tomato|Gecko/20100315'){
return 403;
}
}
本文出自 “echo xiayun” 博客,转载请与作者联系!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: