首页 > 解决方案 > 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; 
}

更多信息:

非常感谢任何帮助!

标签: nginxwebservernginx-reverse-proxyjwilder-nginx-proxy

解决方案


推荐阅读