码迷,mamicode.com
首页 > 其他好文 > 详细

nginx访问控制配置

时间:2015-06-08 15:14:59      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:配置文件   include   local   命名   

限制只让某个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;

}

}


nginx访问控制配置

标签:配置文件   include   local   命名   

原文地址:http://881955.blog.51cto.com/871955/1659590

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!