gpt4 book ai didi

nginx - 使用 NGINX auth_request 和 oauth2_proxy 设置 header

转载 作者:行者123 更新时间:2023-12-03 12:08:37 84 4
gpt4 key购买 nike

我想用 auth_requestoauth2_proxy在成功的身份验证请求时设置 header ,然后将其传递给将处理实际请求的下一个内联代理。

我已经设置了 NGINX 和各种代理来做他们的事情,但是我不确定如何从我用于身份验证请求的服务器(图中的 AUTH PROXY)设置 header ,以便将该 header 传递给下一个服务器(图中的后端服务器)

NGINX ---- auth request ----> AUTH PROXY
|
| <--- 201 <------ SUCCESS
|
----> underlying request ----> BACKEND SERVER

我的 NGINX 配置看起来像
server {                                                       
listen 9123;
resolver 10.3.0.2;
resolver_timeout 30;

location / {
auth_request /_auth;
proxy_set_header x-user $http_x_user;
proxy_pass http://backend_server;
}

location = /_auth {
internal;
proxy_pass https://auth;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
}

当我发出实际请求时,我在 NGINX 调试日志中看到以下内容(这是来自身份验证服务器的响应的一部分):
2013/10/14 17:46:42 [debug] 31222#0: *4 http proxy header: "Content-Type: text/html; charset=utf-8"    
2013/10/14 17:46:42 [debug] 31222#0: *4 http proxy header: "Date: Mon, 14 Oct 2013 17:46:42 GMT"
2013/10/14 17:46:42 [debug] 31222#0: *4 http proxy header: "Server: nginx/1.2.5"
2013/10/14 17:46:42 [debug] 31222#0: *4 http proxy header: "Vary: Cookie"
2013/10/14 17:46:42 [debug] 31222#0: *4 http proxy header: "x-user: 1"

我要搭 x-user header 并将其传递到后端服务器。

我在 location / 中尝试了各种组合阻止但他们都没有工作。例如。
  • proxy_set_header x-user $upstream_http_x_user;
  • proxy_set_header x-user $http_x_user;
  • proxy_set_header x-user $sent_http_x_user;
  • proxy_pass_header x-user

  • 这些似乎都不起作用。我有什么想法可以完成这项任务吗?请注意,这是设置我想传递给后端服务器的 header 的身份验证代理,

    最佳答案

    晕,想通了。正确的 NGINX 配置如下所示:

    location / {                                               
    auth_request /_auth;
    auth_request_set $user $upstream_http_x_user;
    proxy_set_header x-user $user;
    proxy_pass http://backend_server;
    }

    问题是您不能将标题直接分配给另一个标题,您必须使用 auth_request_set将标题设置为变量,然后将该变量分配给标题。

    关于nginx - 使用 NGINX auth_request 和 oauth2_proxy 设置 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19366215/

    84 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com