Nginx的授权(401)问题

时间:2016-09-27 15:41:00

标签: nginx

我有一个Nginx虚拟主机,其中包含以下内容:

server {
    listen 80;
    location /.well-known {
        alias /usr/local/etc/letsencrypt-webroot/.well-known;
    }
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/sub.domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/sub.domain.com/privkey.pem;
    ssl_dhparam /etc/nginx/ssl/dh.pem;

        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_cookie_path / "/; secure; HttpOnly";
        auth_basic "No no no!";
        auth_basic_user_file /etc/nginx/.htpasswd;
    }
}

当网址为/.well-known/...时,我遇到了问题。我得到401因为它一直要求凭据。

所以我的问题是:

  • 为什么/.well-known受到用户保护?是否应该在到达SSL部分location /之前处理它,这是需要身份验证的部分?

  • 我该如何解决这个问题?基本上我需要向代理请求的所有内容都需要身份验证,但/.well-known除外。

1 个答案:

答案 0 :(得分:0)

尝试打开http://yourserver/.well-known/而不是https://yourserver/.well-known

如果这有效,则重新考虑将两个位置块移动到单个iOS块。

//编辑以使其正常工作您必须从中删除重定向。众所周知的阻止或将其添加到https服务器定义中的阻止。