45IT.COM- 电脑学习从此开始!
DIY硬件教程攒机经验装机配置
设计Photoshop网页设计特效
系统注册表DOS系统命令其它
存储主板显卡外设键鼠内存
维修显卡CPU内存打印机
WinXPVistaWin7unix/linux
CPU光驱电源/散热显示器其它
修技主板硬盘键鼠显示器光驱
办公ExcelWordPowerPointWPS
编程数据库CSS脚本PHP
网络局域网QQ服务器
软件网络系统图像安全
页面导航: 首页 > 电脑学院 > 服务器技术 >

nginx中针对目录进行IP限制

电脑软硬件应用网 45IT.COM 时间:2013-06-25 12:41 作者:佚名

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;
                      }
 
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
无法在这个位置找到: baidushare.htm
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
验证码:点击我更换图片
推荐知识