gpt4 book ai didi

nginx - 阻止访问目录中的文件但允许 index.html

转载 作者:行者123 更新时间:2023-12-04 16:34:34 26 4
gpt4 key购买 nike

我在/test/上托管一个网站,但如果用户知道文件名,则可以通过转到 url 来访问文件。前任:

domain.com/test/readmesample.txt

我像上面一样设置了它,但是现在当我去 domain.com/test 时,index.html 文件不会加载并且我收到 403 禁止。

我如何设置它以便在进入/test 时它允许加载 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更多。

关于nginx - 阻止访问目录中的文件但允许 index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42558842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com