ede*_*isn 5 nginx auth-request
我使用 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;
}
}
Run Code Online (Sandbox Code Playgroud)
但我的重定向不起作用。我的配置出了什么问题?
小智 -1
你说它不起作用是什么意思?我假设您没有重定向,但是请求的状态代码是什么?/auth 子请求的状态码是什么?你在哪个 nginx 上测试它?您检查过错误/访问日志吗?
我这么问是因为我拿了你的代码,在 Nginx 1.19.1 上运行并且运行良好。当 /auth 子请求返回 401 错误时,我将通过 @auth location 进行重定向。我们可以在这里改进一件事。您不需要检查 $backend_status 变量是否等于 401,如果 Nginx 将请求传递到 @auth 位置,则意味着我们有来自 /auth 的 401 :)
兄弟,皮奥特
归档时间: |
|
查看次数: |
5192 次 |
最近记录: |