我一直在尝试在SSL网站上设置密码保护的目录,如下所示:
在/ etc / nginx的/网站可用/默认
server { listen 443: ssl on; ssl_certificate /usr/certs/server.crt; ssl_certificate_key /usr/certs/server.key; server_name server1.example.com; root /var/www/example.com/htdocs/; index index.html; location /secure/ { auth_basic "Restricted"; auth_basic_user_file /var/www/example.com/.htpasswd; } }
问题是当我尝试访问URL https://server1.example.com/secure/ ,我得到一个“404:找不到”的错误页面。
我的error.log显示以下错误:
011/11/26 03:09:06 [error] 10913#0: *1 no user/password was provided for basic authentication, client: 192.168.0.24, server: server1.example.com, request: "GET /secure/ HTTP/1.1", host: "server1.example.com"
但是,我能够正常的HTTP虚拟主机设置密码保护的目录没有任何问题。
这是configuration还是其他的问题?
可能这是auth_basic_user_file的path问题,你的绝对path令人困惑nginx:
http://wiki.nginx.org/HttpAuthBasicModule#auth_basic_user_file
从版本0.6.7开始,文件名path是相对于nginxconfiguration文件nginx.conf的目录,而不是nginx的前缀目录。
我不确定你在其他情况下是如何工作的。 从文档引述表明,你应该有这样的东西:
auth_basic_user_file htpasswd/www.example.com
如果您有“/etc/nginx/nginx.conf”作为您的服务器configuration文件,那么您将密码文件设置为“/etc/nginx/htpasswd/www.example.com”。
你可以通过运行“sudo nginx -t”来检查nginxconfiguration。 如果有configuration错误,即auth文件不在预期的位置,它应该告诉你。