小编mon*_*de_的帖子

nginx auth_basic 是否可以通过 HTTPS 工作?

我一直在尝试在 SSL 网站中设置受密码保护的目录,如下所示:

/etc/nginx/sites-available/default

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是当我尝试访问 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"
Run Code Online (Sandbox Code Playgroud)

但是,我能够为普通的 HTTP 虚拟主机设置受密码保护的目录,没有任何问题。

是配置有问题还是别的什么?

nginx https password-protected

5
推荐指数
1
解决办法
6232
查看次数

标签 统计

https ×1

nginx ×1

password-protected ×1