gpt4 book ai didi

NGINX - 身份验证失败时重定向

转载 作者:行者123 更新时间:2023-12-02 04:36:20 25 4
gpt4 key购买 nike

我正在尝试找到一种方法,在用户提供无效凭据或根本没有提供凭据的情况下将用户重定向到其他位置。

我的配置是这样的:

 server {
listen 9999;

auth_basic "Authentication Required";
auth_basic_user_file passwords;

这会导致用户的浏览器不断提示输入凭据,直到他取消提示 - 这会返回 401 错误。

如果身份验证失败(无论出于何种原因),我想将用户重定向到另一个页面 - 这对 NGINX 可行吗?

最佳答案

工作正常。只需确保您的 placeholder.html 存在即可。否则它将通过 404。

    server {
listen 80;
server_name testing.com;

root /var/www/;

location / {
index index.html index.htm;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
error_page 401 /placeholder.html;
location = /placeholder.html {
auth_basic off;
}

}

关于NGINX - 身份验证失败时重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42328822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com