【问题标题】:Pass a custom fixed header to auth_request in nginx将自定义的固定标头传递给 nginx 中的 auth_request
【发布时间】:2021-02-22 01:05:48
【问题描述】:

我需要一些指导才能将静态标头传递给 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 标头的一部分传递,因为它是一个内部进程。

【问题讨论】:

  • 这个CallType 标头是否应该同时传递给myaddservice.com:8080authserver.com:8009
  • 不..我只是在 authserver.com 中需要它..即使传递给两者也不会产生影响..我也可以...任何帮助

标签: nginx auth-request


【解决方案1】:

你可以试试这个:

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 标头根本不会设置(如果空值是,nginx 不会设置标头)作为参数传递给add_headerproxy_set_header 指令)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    • 2014-08-17
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-19
    相关资源
    最近更新 更多