在 nginx 中将自定义固定 header 传递给 auth_request
Pass a custom fixed header to auth_request in nginx
我需要一些指导来在 nginx 中将静态 header 传递给 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 header 传递给 auth_request.I 已尝试使用 add_header、proxy_set_header 但没有成功。
我有一个 Rest Api 在 auth_request 后面进行身份验证,它需要 CallType header.
我无法让它作为 api header 的一部分通过,因为它是一个内部流程。
你可以试试这个:
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/;
}
如果将从其他位置调用身份验证请求,$calltype
变量将具有空值并且 CallType
header 根本不会被设置(nginx如果将空值作为参数传递给 add_header
或 proxy_set_header
指令,则不会设置 header。
我需要一些指导来在 nginx 中将静态 header 传递给 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 header 传递给 auth_request.I 已尝试使用 add_header、proxy_set_header 但没有成功。
我有一个 Rest Api 在 auth_request 后面进行身份验证,它需要 CallType header.
我无法让它作为 api header 的一部分通过,因为它是一个内部流程。
你可以试试这个:
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/;
}
如果将从其他位置调用身份验证请求,$calltype
变量将具有空值并且 CallType
header 根本不会被设置(nginx如果将空值作为参数传递给 add_header
或 proxy_set_header
指令,则不会设置 header。