我实际上使用 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。
我希望你能帮我一把。
亲切的问候!!!
您可能需要进行一些更改:
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$ {
...
}
}
}
一般来说,root
and index
指令被放置在server
块级别,以便所有location
块继承相同的值。看这个文件 http://nginx.org/en/docs/http/ngx_http_core_module.html#root了解详情。
我假设你有一个location ~ \.php$
当前执行所有 PHP 脚本的块。
我的示例使用前缀位置^~
修饰符,而不是正则表达式位置。修饰符使其优先,无论在范围内的位置如何server
堵塞。看这个文件 http://nginx.org/en/docs/http/ngx_http_core_module.html#location了解详情。
的最后一个元素try_files
指令是一个 URI,这意味着它必须包含/subdir
前缀,如果您特别想要该文件夹中的文件。看这个文件 http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files了解详情。
你需要复制另一个location ~ \.php$
内location ^~ /subdir
块,以便 PHP 脚本受到相同访问规则的保护。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)