bas*_*iat 2 nginx nginx-reverse-proxy
我按照配置子请求身份验证/auth_request /auth;
中的描述进行操作
如果 /auth 返回 401 或 403,如何重定向到登录页面?
我尝试过
error_page 401 403 = @error401;
location = ^/securedUrl {
add_header dbg-header dbg_ws_3;
auth_request /auth;
proxy_pass http://auth-module:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass_header x-remaining-session-time;
}
location @error401 {
return 302 /login-module/login;
}
location = /auth {
internal;
rewrite ^/(.*) /is-authorized break;
proxy_pass http://auth-module:8080;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用,我在浏览器中收到 401
使用代理请求时,应设置“proxy_intercept_errors on;” 在该位置。像这样:
location = ^/securedUrl {
add_header dbg-header dbg_ws_3;
auth_request /auth;
proxy_pass http://auth-module:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass_header x-remaining-session-time;
}
location @error401 {
return 302 /login-module/login;
}
location = /auth {
internal;
rewrite ^/(.*) /is-authorized break;
proxy_pass http://auth-module:8080;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_intercept_errors on;
error_page 401 = @error401;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7534 次 |
| 最近记录: |