繁体   English   中英

nginx 代理请求使用来自身份验证 http 请求的标头值提供服务

[英]nginx proxy request to service with header value from an authentication http request

这就是我想要实现的目标:

在此处输入图片说明

我想使用 nginx 作为经典的反向代理来公开服务器的资源。 在调用服务器之前,nginx 应该向令牌颁发者(一个内部服务)请求一个令牌,并将这个令牌注入到服务器调用的身份验证标头中。

使用 nginx 可以实现这一点吗? 我环顾了 nginx 文档,我知道我可以使用proxy_set_header来修改代理到服务器的标头。

更新

我能够使下面的解决方案起作用; 这是github上的一个POC

如果您可以让您的令牌发行者通过某些 HTTP 标头(例如X-JWT-Token ,那么这里是一个适合您的示例:

location /auth {
    internal;
    proxy_pass http://token-issuer;
    proxy_pass_request_body off;
    proxy_set_header Content-Length 0;
    # You can pass an additional data for the token issuer, for example
    # proxy_set_header X-Original-URI $request_uri;
}
location / {
    auth_request /auth;
    auth_request_set $token $upstream_http_x_jwt_token;
    proxy_set_header Authorization "Bearer $token";
    proxy_pass http://upstream;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM