nginx限制ip访问权限
来源:互联网 发布:linux varlog 删除 编辑:程序博客网 时间:2024/05/01 11:15
一、服务器全局限IP
#vi nginx.conf
allow 10.57.22.172;
deny all;
二、站点限IP
#vi vhosts.conf
站点全局限IP:
location / {
index index.html index.htm index.php;
allow 10.57.22.172;
deny all;
location ~ \.php$ {
if ( $fastcgi_script_name ~ \..*\/.*php ) {return 403;}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/htdocs$fastcgi_script_name;
include fastcgi_params;
}
}
站点IP限目录:
location / {
index index.html index.htm index.php;
}
location ^~ /liuwx/ {
allow 10.57.22.172;
deny all;
if ( $fastcgi_script_name ~ \..*\/.*php ) {return 403;}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/htdocs$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.php$ {
if ( $fastcgi_script_name ~ \..*\/.*php ) {return 403;}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/htdocs$fastcgi_script_name;
include fastcgi_params;
}
注意事项:
1. deny 一定要加一个ip,否则直接跳转到403,不往下执行了;如果403默认页是同一域名下,会造成死循环访问;
2. allow的ip段
从允许访问的段位从小到大排列,如127.0.0.0/24 下面才能是10.10.0.0/16
24表示子网掩码:255.255.255.0
16表示子网掩码:255.255.0.0
8表示子网掩码:255.0.0.0
3. deny all;结尾 表示除了上面allow的其他都禁止
如:
#vi nginx.conf
allow 10.57.22.172;
deny all;
二、站点限IP
#vi vhosts.conf
站点全局限IP:
location / {
index index.html index.htm index.php;
allow 10.57.22.172;
deny all;
location ~ \.php$ {
if ( $fastcgi_script_name ~ \..*\/.*php ) {return 403;}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/htdocs$fastcgi_script_name;
include fastcgi_params;
}
}
站点IP限目录:
location / {
index index.html index.htm index.php;
}
location ^~ /liuwx/ {
allow 10.57.22.172;
deny all;
if ( $fastcgi_script_name ~ \..*\/.*php ) {return 403;}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/htdocs$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.php$ {
if ( $fastcgi_script_name ~ \..*\/.*php ) {return 403;}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/htdocs$fastcgi_script_name;
include fastcgi_params;
}
注意事项:
1. deny 一定要加一个ip,否则直接跳转到403,不往下执行了;如果403默认页是同一域名下,会造成死循环访问;
2. allow的ip段
从允许访问的段位从小到大排列,如127.0.0.0/24 下面才能是10.10.0.0/16
24表示子网掩码:255.255.255.0
16表示子网掩码:255.255.0.0
8表示子网掩码:255.0.0.0
3. deny all;结尾 表示除了上面allow的其他都禁止
如:
deny 192.168.1.1; allow 127.0.0.0/24; allo w 192.168.0.0/16; allow 10.10.0.0/16; deny all;
转自:http://hi.baidu.com/woaidelphi/item/31ef1a267f2b4e8a6e2cc340?qq-pf-to=pcqq.c2c
0 0
- nginx限制ip访问权限
- nginx限制ip访问 nginx访问权限
- Nginx限制ip访问
- nginx限制IP访问
- nginx限制IP访问
- Nginx限制ip多次访问
- nginx apache限制ip并发访问 限制ip连接
- nginx指定目录ip访问限制
- nginx配置二:限制来源ip访问
- nginx限制ip访问,进行认证
- nginx添加ip访问频率限制
- nginx添加ip访问频率限制
- 为nginx添加ip访问频率限制
- Nginx通过ip和user_gent限制访问
- Nginx配置location限制IP访问策略
- 基于IP配置Nginx的访问权限-
- nginx中限制通过ip访问网站的方法
- nginx限制某个IP同一时间段的访问次数
- Twitter 宣布收购社交数据提供商 Gnip
- 我的简历
- B. Mashmokh and ACM
- 《Java解惑》系列——01表达式之谜——谜题07:互换内容
- UIView转场动画 IOS
- nginx限制ip访问权限
- 深入研究用户提升关键词排名
- arm上安装openssh
- Mysql中的char与varchar length()与char_length()
- PHP SPL笔记
- Linux禁止用户登录
- 网络营销是企业必不可少的
- struts2 标签库
- 优秀的iOS开源项目