nginx - Nginx 身份验证在根页面(HTTPS)上不起作用
问题描述
我已经使用以下代码配置了 Nginx 身份验证,它向我展示了一些奇怪的行为。
server {
listen 5000;
server_name localhost;
location / {
proxy_pass http://frp_server:4200;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
auth_basic "Administrator Area";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location /axis1/ {
proxy_pass http://frp_server:4200;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
auth_basic "Administrator Area";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
通过 https://$DOMAIN/ 访问根域时显示身份验证窗口,但登录时无法识别保存在 .htpasswd 文件中的用户。一旦我将应用程序放在另一个 URL 上(以下 /axis1/例如),身份验证突然起作用。
在服务端口后面添加斜杠时,身份验证也不起作用:
location /axis1/ {
proxy_pass http://frp_server:4200/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
auth_basic "Administrator Area";
auth_basic_user_file /etc/nginx/.htpasswd;
}
更多信息:
- Nginx 代理将域 $SUBDOMAIN.$DOMAIN.com 指向 Nginx 脚本,因此通过 https://$SUBDOMAIN.$DOMAIN.com 访问网络服务器。此外,Nginx 在 Docker(与 Nginx-Proxy 相同的网络)中运行。
非常感谢任何帮助!
解决方案
推荐阅读
- html - Django ERR_EMPTY_RESPONSE
- python - 在硬币翻转功能中循环重复
- firebase - 未处理的异常:“String”类型不是“num”类型的子类型
- excel - 偏移选定范围内的最大数字
- python - 我怎样才能让正则表达式删除冗余并再次调用自己?
- javascript - 如何从对象数组中提取数据以在 html 电子邮件模板中呈现列表?使用 React/Formik/Sendgrid
- oracle - Oracle Data Modeller:递归的一对多关系
- python-3.x - 如示例中所示合并 2 个不同的列表
- r - 有没有办法确定威布尔分布的形状和尺度参数,而只有一个值可用于故障之间的时间?
- javascript - 通过 NodeJS 在 Raspberry 上运行 bash 脚本