我正在/ test /上托管一个网站,但如果用户知道文件名,可以通过访问网址来访问文件.例如:
domain.com/test/readmesample.txt
我有它像上面设置但现在当我去domain.com/test index.html文件不会加载,我得到403禁止.
如何进行设置,以便在进行/测试时允许加载html文件,同时仍然阻止该目录中的文件?这包括index.html以外的文件,文件夹和.files.
location ~ /test {
deny all;
}
这是我的配置文件
server {
listen 80;
listen 443 ssl default_server;
root /config/www;
index index.html index.htm index.PHP;
server_name www.domain.com;
ssl_certificate /config/keys/letsencrypt/fullchain.pem;
ssl_certificate_key /config/keys/letsencrypt/privkey.pem;
ssl_dhparam /config/Nginx/dhparams.pem;
ssl_ciphers 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
ssl_prefer_server_ciphers on;
client_max_body_size 0;
location / {
try_files $uri $uri/ /index.html /index.PHP?$args =404;
}
location ~ /new {
deny all;
}
location ~ \.PHP${
fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
# With PHP5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# With PHP5-fpm:
#fastcgi_pass unix:/var/run/PHP5-fpm.sock;
fastcgi_index index.PHP;
include /etc/Nginx/fastcgi_params;
}
先感谢您
解决方法:
你可以用以下方法明确地打破/test/index.html:
location = /test/index.html {
}
location ^~ /test {
deny all;
}
精确匹配位置具有最高优先级,并且^〜修饰符将前缀位置的优先级置于同一级别的正则表达式位置之上.
有关更多信息,请参见this document
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。