我有一个Nginx服务器,并禁用nginx_vhost.conf
隐藏文件
## Disable .htaccess and other hidden files location ~ /\. { deny all; access_log off; log_not_found off; }
但是,LetsEncrypt需要访问.well .well-known
目录。
如何允许.well-known
目录并拒绝其他隐藏的文件?
我已经提供了一个关于如何在我的网站上使用Let's Encrypt与NGINX的完整的一步一步的教程。
关键部分是:
你根本不需要你的https模块中的监听器,这些都是在https上完成的。 这只是为了certificate你控制的领域,它不提供任何私人或秘密。
# Answer let's encrypt requests, but forward everything else to https server { listen 80; server_name example.com www.example.com access_log /var/log/nginx/access.log main; # Let's Encrypt certificates with Acmetool location /.well-known/acme-challenge/ { alias /var/www/.well-known/acme-challenge/; } location / { return 301 https://www.example.com$request_uri; } }
上面链接完整的一步一步的指导。
Nginx使用正则expression式按照它们在configuration文件中出现的顺序应用位置。
因此, 在您当前的位置之前添加这样的条目将有助于您。
location ~ /.well-known { allow all; }
其他解决scheme并没有帮助我。
我的解决scheme是包含一个负面的正则expression式 。 你的代码块应该如下所示:
## Disable .htaccess and other hidden files location ~ /\.(?!well-known).* { deny all; access_log off; log_not_found off; }
它会阻止除了以.well-known
开头的所有点文件
PS:我也会加return 404;
到块。
添加(在之前或之后):
location ^~ /.well-known/ { log_not_found off; }
在阅读文档并尝试之后find答案。