我在/ test /上托管一个网站,但是如果用户知道文件名,可以通过转到url来访问文件。例如:
domain.com/test/readmesample.txt
Run Code Online (Sandbox Code Playgroud)
我有如上所述的设置,但是现在当我转到domain.com/test时,不会加载index.html文件,并且我禁止了403。
我如何设置它,以便在进入/ test时允许html文件加载,同时仍然阻止该目录中的文件?其中包括index.html以外的文件,文件夹和.files。
location ~ /test {
deny all;
}
Run Code Online (Sandbox Code Playgroud)
这是我的配置文件
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;
}
Run Code Online (Sandbox Code Playgroud)
先感谢您
你可以明确地打破/test/index.html:
location = /test/index.html {
}
location ^~ /test {
deny all;
}
Run Code Online (Sandbox Code Playgroud)
精确匹配位置具有最高优先级,并且^~修饰符将前缀位置的优先级置于同一级别的正则表达式位置之上。
请参阅此文档了解更多信息。
| 归档时间: |
|
| 查看次数: |
7351 次 |
| 最近记录: |