版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/diyiday/article/details/81875658
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………;
}
一样的效果