【发布时间】:2020-07-14 21:27:54
【问题描述】:
我有一个要求,当代理响应错误代码为 401(条件 #1)且响应正文包含文本“无 SAML 令牌”(条件 #2)时,我需要拦截它并重定向到刷新令牌 API。
在只考虑错误代码 401 的情况下,我可以部分执行此操作。无法找到一种方法来读取响应正文以提供 条件 #2:
location /service {
proxy_intercept_errors on;
error_page 401 = @refresh;
}
location @refresh {
(# Here check if the response body has text "No SAML Token". If yes return 401 directly.)
set $original_uri $scheme://$http_host$request_uri;
return 307 https://localhost:8083/service/auth/refresh?uri=$original_uri;
}
请帮助我获取响应正文。提前致谢!
【问题讨论】:
标签: nginx nginx-reverse-proxy nginx-location nginx-config