NGINX-身份验证失败时重定向 [英] NGINX - Redirect on auth failure
本文介绍了NGINX-身份验证失败时重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果用户提供的凭据无效或根本没有凭据,我正在尝试将用户重定向到其他位置的方法.
I'm trying to find a way to redirect a user to a different location, if he provides invalid credentials, or no credentials at all.
我的配置如下:
server {
listen 9999;
auth_basic "Authentication Required";
auth_basic_user_file passwords;
这会导致用户的浏览器不断提示输入凭据,直到他取消提示-这将返回401错误.
This causes the user's browser to constantly prompt for credentials, until he cancels the prompt - which returns a 401 error.
如果身份验证失败(无论出于何种原因),我想将用户重定向到其他页面-NGINX是否可以?
I would like to redirect the user to a different page if the authentication failed (for whatever reason) - is this possible with NGINX?
推荐答案
工作正常.
只要确保您的placeholder.html
存在.否则它将通过404.
Working fine.
Just make sure that your placeholder.html
exists. Else it will through 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-身份验证失败时重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文