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” 博客,转载请与作者联系!
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” 博客,转载请与作者联系!
相关文章推荐
- PhpStudy切换到nginx服务器后页面无法打开
- Nginx的学习
- nginx的高级配置(4)——防盗链
- nginx nginx.conf配置说明
- 安装nginx
- Nginx安装及配置文件nginx.conf详解
- nginx软负载的搭建
- nginx + lua 资源防盗链
- nginx优化 突破十万并发
- Nginx请求处理
- nginx+uwsgi部署flask(新)
- nginx location配置详解
- nginx转发urlencode编码
- Nginx/LVS/HAProxy负载均衡软件的优缺点详解
- lvs、haproxy、nginx 负载均衡的比较分析
- Linux 下的Nginx的下载与安装
- windows下配置nginx+php环境
- 使用Nginx作为负载均衡器
- nginx 源码学习笔记(十五)—— ngx_master_process_cycle 多进程(一)
- nginx源码分析—全局变量ngx_cycle的初始化