【发布时间】:2019-03-07 13:27:23
【问题描述】:
我正在使用 NGINX 运行我的网站,我想启用对网站的身份验证,所以我做到了,使用 .htpasswd 文件并且它有效,这是我的 default.conf 文件的一部分:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
auth_basic "Administrator Login";
auth_basic_user_file /usr/share/nginx/html/.htpasswd;
location / {
root /usr/share/nginx/html;
index index.html index.html;
}
它可以工作,这样我的整个页面都需要身份验证,现在我想让“公共”文件夹在没有身份验证的情况下可用,所以我遵循official NGNIX docs 并将这个指令添加到我的 default.conf
location /public/ {
auth_basic off;
}
但现在的问题是,每次我尝试从公用文件夹访问某些文件时,比如 http://mywebsite.com/public/test.html,如果我删除,我就会不断收到“404 Not Found”这来自我的 default.conf:
location /public/ {
auth_basic off;
}
我将能够访问http://mywebsite.com/public/test.html,但显然我必须提供身份验证登录名和密码,任何想法都会有所帮助,谢谢。
【问题讨论】:
标签: web nginx nginx-location nginx-config