欢迎来到山村网

nginx中针对目录进行IP限制

2019-03-09 09:40:34浏览:100 来源:山村网   
核心摘要:  nginx phpmyadmin 针对内网ip用户开放、外网ip用户关闭(在前面的配置中,location ~ ^/目录/使用正则,优先级高于location /

  nginx phpmyadmin 针对内网ip用户开放、外网ip用户关闭(在前面的配置中,location ~ ^/目录/使用正则, 优先级高于location /的配置,所以nginx无法对首页进行解析)

代码如下

server {

listen 80;

server_name example.com;

access_log logs/access.log main;

location / {

root html;

index index.php index.html index.htm;

}

location ~ ^/phpmyadmin/ {

allow 192.168.1.0/24;

deny all;

location ~ .*.(php|php5)?$ {

root /var/mailapp/nginx/html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

}

location ~ .*.(php|php5)?$ {

root /opt/nginx/html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

}

  我们也可以这样配置

代码如下 server {
listen 80;
server_name example.com;
access_log logs/access.log main;
location / {
root html;
index index.php index.html index.htm;
}
location ~ ^/download/ {
allow 192.168.1.0/24;
deny all;
index index.php index.do index.html index.htm;
location ~ .*.(php|php5)?$ {
root /var/mailapp/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}


location ~ .*.(php|php5)?$ {
root /opt/nginx/html;
astcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
(责任编辑:豆豆)
下一篇:

网络管理员维护技巧

上一篇:

Linux系统中安装和使用Axel下载工具

  • 信息二维码

    手机看新闻

  • 分享到
打赏
免责声明
• 
本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们 xfptx@outlook.com