gpt4 book ai didi

nginx auth_request 重定向

转载 作者:行者123 更新时间:2023-12-04 14:27:34 32 4
gpt4 key购买 nike

我使用 auth_request 模块( http://nginx.org/en/docs/http/ngx_http_auth_request_module.html )。我的 nginx 配置:

auth_request /auth;
auth_request_set $backend_status $upstream_status;

location / {
proxy_pass http://unicorn;

error_page 401 @auth;
}

location = /auth {
internal;
proxy_pass https://proxy_pass_url;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
}

location @auth {
if ($backend_status = "401") {
return 302 https://proxy_pass_url/login? origin=$scheme://$http_host$request_uri;
}
}

但我的重定向不起作用。我的配置有什么问题?

最佳答案

你的意思是它不起作用?我假设您没有重定向,但是请求的状态代码是什么?/auth 子请求的状态码是什么?你在哪个 nginx 上测试它?您是否检查过错误/访问日志?
我问是因为我拿了你的代码,在 Nginx 1.19.1 上运行并且运行良好。当/auth 子请求返回 401 错误时,我通过 @auth 位置重定向。我们可以在这里改进一件事。您不需要检查 $backend_status 变量是否等于 401,如果 Nginx 将请求传递到 @auth 位置,则意味着我们有来自/auth 的 401 :)
溴,
彼得

关于nginx auth_request 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43305293/

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