最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
nginx 设置限制ip访问的教程
时间:2022-06-30 18:28:17 编辑:袖梨 来源:一聚教程网
一、服务器全局限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;
相关文章
- 《一耽女孩》官网入口地址直达 12-21
- 蓝莓影院官网最新入口-2026蓝莓影院电视剧全网免费观看 12-21
- 阿里旺旺网页版在线登录入口-阿里旺旺网页版官方唯一在线入口 12-21
- 学习通网页版登录入口 学校通官方免费在线使用指南 12-21
- 抖币充值官网入口-抖音1:10比例抖币直充链接 12-21
- 百度云盘网页版直达入口-百度网盘网页版快捷登录入口 12-21