nginx限制ip地址
2016-04-17 15:33
627 查看
一、服务器全局限IP
#vi nginx.conf
allow 10.57.22.172; #允许的IP
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 ^~ /test/ {
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://blog.sina.com.cn/s/blog_721cd3390101e8xv.html
#vi nginx.conf
allow 10.57.22.172; #允许的IP
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 ^~ /test/ {
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://blog.sina.com.cn/s/blog_721cd3390101e8xv.html
相关文章推荐
- Nginx配置文件nginx.conf具体解释
- nginx之location配置
- Mac OSX 10.9搭建nginx+mysql+php-fpm环境
- nginx 隐藏index.php 支持PATHINFO
- Nginx使用的php-fpm的两种进程管理方式及优化(转)
- nginx多进程锁的实现
- 分布式架构高可用架构篇_04_Keepalived+Nginx实现高可用Web负载均衡
- 使用Nginx+Lua进行Web开发
- 编译安装nginx
- linux+nginx+mysql+php
- Nginx启动/重启失败
- nginx的server_name配置
- [转] nginx 开启gzip压缩--字符串压缩比率很牛叉
- Apacche与Nginx优缺点比较
- nginx配置性能优化
- nginx lvs haproxy负载优缺点比较
- 基于Nginx1.9+LuaJIT+Kafka的点播监控系统实战(上海卓越智慧树网点播监控系统)
- nginx 一二事(1) - 简单图片服务器解决方案
- nginx 父子进程通信 channel
- Nginx与Lua