nginx 拦截html页面,nginx – 阻止访问目录中的文件但允许index.html

我正在/ 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;

}

先感谢您

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值