1、要禁止所有IP访问a1.htm a2.htm a3.htm这个三个页面在location可以这样写
location ~* /(a1.htm|a2.htm|a3.htm)$ { deny all; condition………; }
2、只允许指定的ip访问a1.htm a2.htm a3.htm这个三个页面,其他IP的访问都拒绝
location ~* /(a1.htm|a2.htm|a3.htm)$ { allow 10.0.0.2; deny all; condition………; }
这种设置只有ip地址为10.0.0.2的主机可以放问这三个页面,其他的ip都被拒绝了。
其他情况可以以此类推。
比如我需要指定只能8.8.8.8这个ip访问info.php页面。那么就可以在nginx-server中添加如下配置,即可
如果非8.8.8.8访问info.php页面,则返回403
后面需要加上跳转地址,proxy_pass http://192.168.1.110:10480;否则会404错误。
location ~/info.php$ { if ($remote_addr != '8.8.8.8' ) { return 403; } proxy_pass http://192.168.1.110:10480; } }
也可以在server代码中添加
location ~/info.php$ { allow 8.8.8.8; deny all; condition………; }
一样的效果
如何配置禁用ip或ip段呢?
下面说明假定nginx的目录在/usr/local/nginx/
首先要建一个封ip的配置文件blockips.conf,然后vi blockips.conf编辑此文件,在文件中输入要封的ip。
deny 1.2.3.4; deny 91.212.45.0/24; deny 91.212.65.0/24;
然后保存此文件,并且打开nginx.conf文件,在http配置节内添加下面一行配置:
include blockips.conf;
保存nginx.conf文件,然后测试现在的nginx配置文件是否是合法的:
/usr/local/nginx/sbin/nginx -t
如果配置没有问题,就会输出:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
如果配置有问题就需要检查下哪儿有语法问题,如果没有问题,需要执行下面命令,让nginx重新载入配置文件。
/usr/local/nginx/sbin/nginx -s reload
只允许某些的ip访问页面,或者禁止某些ip访问页面
server_name es.mila66.com; location / { include /etx/nginx/all/ip.conf; deny all;
ip.conf里面的文件格式:
allow 192.168.1.11;
allow 192.168.1.12;
这样就实现了只允许某些ip访问页面。
如果禁止某些IP访问,只需要修改如下:把allow改成deny即可。
server_name es.mila66.com; location / { include /etx/nginx/all/ip.conf; allow all;
ip.conf里面的文件格式:
deny 192.168.1.11;
deny 192.168.1.12;
nginx -s reload
重启服务器即可
以上这篇Nginx限制IP访问某些页面的操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
Nginx,限制,IP访问
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 群星《歌手2024 第4期》[FLAC/分轨][563.76MB]
- RiffKitten-ChaosParade(2024)[24-44,1]FLAC
- RuneKlakegg-Nattevandrer(2024)[24-96]\FLAC
- 赖冰霞.2006-金嗓典藏辑2IN1(南方金点系列)2CD【南方】【WAV+CUE】
- 群星.1988-国语金曲尽精英VOL.2【瑞成】【WAV+CUE】
- 张宇.1999-雨一直下【EMI百代】【WAV+CUE】
- 袁娅维.2021-月亮失眠了(DELUXE)【华纳】【FLAC分轨】
- AlanBroadbent-JazzFunk(2024)[24-44,1]
- 梅艳芳《绝代芳华》开盘母带[低速原抓WAV+CUE]
- ABC唱片-《外国精逊母带直刻神奇黑胶[APE+CUE].
- 群星《天赐的声音第五季 第6期》[320K/MP3][101.43MB]
- 群星《天赐的声音第五季 第6期》[FLAC/分轨][526.16MB]
- 群星《说唱梦工厂 第2期》[320K/MP3][96.37MB]
- 杨宗宪.1994-留你留袂着【有容唱片】【WAV+CUE】
- 李翊君.2005-勇敢的爱【创意唱片】【WAV+CUE】