Nginx - 自定义登录页面

riv*_*vki 7 nginx

我正在尝试使用 nginx 基本身份验证来保护我的 web 应用程序。

我正在寻找的是一种强制浏览器显示我的自定义 html 登录页面而不是默认登录弹出窗口但仍处理授权过程的方法。

我尝试省略“WWW-Authenticate”标头,但未显示弹出窗口,但我不知道如何强制浏览器为每个请求添加“授权”标头。

特此 nginx.conf:

location /{
            auth_basic "Restricted";
            auth_basic_user_file htpasswd;
            proxy_pass http://tomcat:8080/;
            error_page 401  /login.html;
    }

    location = /login.html {
            root html;
    more_clear_headers 'WWW-Authenticate';              
    }
Run Code Online (Sandbox Code Playgroud)

Ste*_* E. -3

如果你真的想这样做。最简单的方法是将用户名和密码放入 url 中。基本身份验证支持这一点。将所有请求更改为以下格式,它将起作用:

"http://" + username + ":" + password + "@example.com"
Run Code Online (Sandbox Code Playgroud)