2016-11-04 232 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

你好理查德史密斯,我已经按照你的建议和它的作品应用了更改!!! 非常感谢您的帮助。 亲切的问候! –