TL:博士,如果请求使用nginx的error_page指令重定向,我怎么能确保自定义头与此重定向通过。Nginx的传递HTTP头通过error_page重定向
我目前正在实现一个系统,其中nginx对LDAP服务器进行身份验证并充当反向代理。它基于此https://www.nginx.com/blog/nginx-plus-authenticate-users/ 它的工作方式是,它有一个全能的服务器模块,它将请求发送到在另一个端口上运行的认证页面,这会根据cookie的内容返回403或200 。如果这是403,则用户被发送到登录页面(如果200到达目的地)。
nginx conf的示例如下: location/{ auth_request/auth-proxy;
# redirect 401 to login form
error_page 401 =200 /login;
proxy_pass http://backend/;
}
location /login {
proxy_pass http://backend/login;
# Login service returns a redirect to the original URI
# and sets the cookie for the ldap-auth daemon
proxy_set_header X-Target $request_uri;
}
location = /auth-proxy {
internal;
# The ldap-auth daemon listens on port 8888, as set
# in nginx-ldap-auth-daemon.py.
# Change the IP address if the daemon is not running on
# the same host as NGINX/NGINX Plus.
proxy_pass http://127.0.0.1:8888;
的问题是,我做的改变,使认证兼职并返回一个403码,而不管该cookie是否有效。不过,我想让用户知道登录页面发生了这种情况,因此Python身份验证代码会设置带有错误值的X-authenticationfail标头。
我检查了这部作品通过使用curl发送超时cookie来验证码,并读取头回来。然而,当登录python代码被调用时,这个头信息已经消失。我认为这是由于nginx不转发它。我试图包含“proxy_set_header X-authenticationfail $ http_x_authenticationfail;”,“add_header X-authenticationfail”这样的行“test”always;“在error_page指令之前,但这不起作用。我也尝试过在同一地点使用“proxy_pass_header X-authenticationfail”,但这也失败了。
服务器块具有“上proxy_pass_request_headers”设置设置“上underscores_in_headers”,和。在登录块中,放置“proxy_set_header X-authenticationfail”testvalue“;”获得了登录python代码的价值,并从那里回到浏览器。
感谢您获得这么多!
简而言之'proxy_set_header X-Authenticationfail $ sent_http_x_authenticationfail'在'/ login'位置 –
只是去尝试,仍然没有运气, – James
另外把'$ auth_request_set $ falure_reason sent_http_x_authenticationfail;''下面权auth_request'。你甚至不必在任何地方使用'$ falure_reason'。不知何故,这条线的存在将使我的第一个解决方案工作 –