【问题标题】:Why am I getting "upstream server temporarily disabled while reading response header from upstream"?为什么我会“在从上游读取响应标头时暂时禁用上游服务器”?
【发布时间】:2022-11-30 17:16:00
【问题描述】:

我在 AWS EKS 上部署了 NGINX Plus Ingress 控制器,在入口前我部署了一个网络负载均衡器 (NLB)。我已经在 AWS Cognito 中设置了一个用户池,并根据此处的说明在 NGINX 中设置了 JWT 验证https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-jwt-authentication/#getting-jwks-from-subrequest

auth_jwt             "closed";
auth_jwt_type        signed;
auth_jwt_key_cache   1h;
auth_jwt_key_request /jwks_uri;

...

location = /jwks_uri {
internal;
proxy_pass https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json;
} 

我尝试了各种代理设置 - 从增加超时、设置 proxy_method GET、剥离标头,但似乎没有任何帮助。我还通过添加将子请求部分从等式中删除

location /jwks_uri {
proxy_pass https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json;          
}                                                             

那里的请求成功了,所以我不认为这是防火墙问题。

当我在授权标头中使用 Cognito 发出的有效 JWT 发出请求时,如果我等待超过一分钟,我最终会收到 502 响应。在 NGINX 日志中我可以看到

2022/11/24 08:47:55 [warn] 56#56: *19 upstream server temporarily disabled while reading response header from upstream, client: 10.10.20.57, server: <server>, request: "POST /graphql HTTP/1.1", subrequest: "/jwks_uri", upstream: <jwks-uri>", host: <host

这似乎发生在 NGINX 尝试子请求从 AWS 从 https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json 获取 jwks 密钥时

【问题讨论】:

    标签: nginx amazon-eks nlb


    【解决方案1】:

    原始请求是 POST,我需要添加以下代理设置,以便子请求充分转换为 GET

    location = /jwks_uri {
            internal;
            proxy_method GET;
            proxy_set_header Host {idp}.{region}.amazonaws.com;
            proxy_set_header Content-Length "";
            proxy_pass https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json;
          }
    

    发帖以防其他人遇到同样的问题。

    【讨论】:

      猜你喜欢
      • 2021-02-04
      • 2015-01-27
      • 2018-10-15
      • 2017-04-09
      • 2020-01-15
      • 1970-01-01
      • 2019-12-21
      • 2017-04-01
      • 2013-09-15
      相关资源
      最近更新 更多