为什么忽略 nginx my "auth_basic off" for sub-path location 指令?

Why ignores nginx my "auth_basic off" for sub-path location directive?

Nginx (docker image, 1.17.2) 需要对子路径进行基本身份验证。尽管我的配置对 https://example.org/subpath:

另有说明
//  /etc/nginx/conf.d/mysetup.conf

ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

server {
    listen 443 ssl;
    server_name example.org;
    server_tokens off;

    ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    access_log /var/logs/nginx/example.org.access.log;
    error_log /var/logs/nginx/example.org.error.log info;

    root /var/www/domains/example.org/stage_root/;        

    location / {
        auth_basic "example.org server";
        auth_basic_user_file /var/htaccess/htaccess_example.org;
    }
    location /subpath {
        auth_basic off;
        root /var/www/domains/example.org/;
    }
}

一些事实:

到目前为止我尝试过的:

恕我直言,这是标准用例,因此我猜是我漏掉了一些小东西,或者我错过了一些上下文知识。

也许 nginx 有一个 locationroot 高于全局 root 的问题?它虽然提供内容..

我还没有尝试过的:

可能重复的问题:

具体来说 this question is quite similar. However it does not have the 'twist' with the different root dir and the answers haven't helped: 1st not working, 2nd 似乎是一个很好的解决方法。

解决方案是在 server 块中设置 auth_basic_user_file 指令,在各个 location 块中设置 auth_basic 指令。

为了清楚起见,我只包含了相关配置。文档根目录和其他强制设置被故意省略了。

server {
    auth_basic_user_file /path/to/auth.txt;
    location /other {
        auth_basic off;
    }
    location / {
        auth_basic "Restricted";
    }
}