2016-11-04 230 views
1

IM實際使用nginx的作爲我的web服務器即時試圖否認使用這一切的子目錄的訪問:IP允許子目錄訪問NGINX

location/{ 
    root /usr/share/nginx/html/project; 
    index index.html index.htm index.php; 
} 



location ~ ^/subdir/ { 
    allow 192.168.1.0/24; 
    deny all; 
    try_files $uri $uri/ /index_subdir.php?$query_string; 
} 

但nginx的嘗​​試找出index_subdir.php項目文件夾內。

我希望你能幫我一把。

親切的問候!

回答

0

你可能需要做一些修改:

server { 
    root /usr/share/nginx/html/project; 
    index index.html index.htm index.php; 

    location/{ 
    } 
    location ~ \.php$ { 
     ... 
    } 

    location ^~ /subdir { 
     allow 192.168.1.0/24; 
     deny all; 

     try_files $uri $uri/ /subdir/index_subdir.php?$query_string; 

     location ~ \.php$ { 
      ... 
     } 
    } 
} 

一般來說,rootindex指令被放置在server塊水平,使所有location塊繼承相同的值。詳情請參閱this document

我假設你有一個location ~ \.php$塊,它當前執行你所有的PHP腳本。

我的示例使用^~修飾符的前綴位置,而不是正則表達式位置。無論server塊中的位置如何,修飾符都會使其優先。詳情請參閱this document

try_files指令的最後一個元素是URI,這意味着它必須包含/subdir前綴(如果您特別需要該文件夾中的文件)。詳細信息請參見this document

您需要在location ^~ /subdir塊內複製另一個location ~ \.php$,以便PHP腳本受相同訪問規則的保護。

+0

你好理查德史密斯,我已經按照你的建議和它的作品應用了更改!!! 非常感謝您的幫助。 親切的問候! –