如何解决将自定义的固定标头传递给Nginx中的auth_request
我需要一些指导,以便将静态标头传递给nginx中的auth_request。
我的位置配置如下:
location = /auth {
internal;
proxy_pass http://authserver.com:8009/auth;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
我的子请求如下所示:
location = /app/finance/ {
proxy_pass_request_headers on;
# Custom header to be added
proxy_set_header CallType "MAJOR";
auth_request /auth;
error_page 401 =401 /auth;
proxy_pass http://myaddservice.com:8080/finance/;
}
我需要将CallType标头传递给auth_request。我尝试使用add_header,proxy_set_header但它没有用。
我有一个Rest Api可以在auth_request后面进行身份验证,这需要CallType标头。
我无法使其作为api标头的一部分传递,因为它是内部过程。
解决方法
您可以尝试以下方法:
location = /auth {
internal;
proxy_pass http://authserver.com:8009/auth;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_set_header CallType $calltype;
}
location = /app/finance/ {
set $calltype "MAJOR";
proxy_pass_request_headers on;
auth_request /auth;
error_page 401 =401 /auth;
proxy_pass http://myaddservice.com:8080/finance/;
}
如果将从其他位置调用auth请求,则$calltype
变量将为空,并且CallType
头将根本不会设置(nginx不会设置头,如果空值作为参数传递给add_header
或proxy_set_header
指令)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。