Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> 電腦軟件教程 >> 服務器技術 >> 關於服務器 >> nginx中針對目錄進行IP限制

nginx中針對目錄進行IP限制

日期:2017/2/8 10:13:01      編輯:關於服務器

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;
                      }
 
Copyright © Windows教程網 All Rights Reserved