pic*_*rob 4 nginx basic-authentication static-content nginx-location
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/;
}
}
Run Code Online (Sandbox Code Playgroud)
一些事实:
server指令中)和上游丛。docker-compose其自己网络设置的一部分(nginx 是网关)/var/www/domains/example.org/subpath/auth_basic会禁用身份验证请求到目前为止我尝试过的:
恕我直言,这是标准用例,因此我猜我漏掉了一些小东西,或者我错过了一些上下文知识。
也许 nginx 有一个高于全局的location块的问题?虽然它服务于内容..rootroot
我还没有尝试过:
allow/ deny,因为它应该在没有 / 的情况下工作可能重复的问题:
具体来说这个问题非常相似。然而,它没有与不同根目录的“扭曲”,并且答案没有帮助:第一个不起作用,第二个似乎是一个解决方法。
auth_basic_user_file解决方案是在块内设置指令server以及auth_basic在各个location块内设置指令。
为了清楚起见,我只包含了相关配置。故意省略文档根目录和其他强制设置。
server {
auth_basic_user_file /path/to/auth.txt;
location /other {
auth_basic off;
}
location / {
auth_basic "Restricted";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2788 次 |
| 最近记录: |