【问题标题】:nginx as reverse proxy returns 502s when upstream server is behind an ALB当上游服务器位于 ALB 后面时,nginx 作为反向代理返回 502s
【发布时间】:2019-08-24 07:10:44
【问题描述】:

我的设置是一个负载均衡器,它连接到一个 nginx 盒子,它充当位于 uwsgi 应用程序前面的负载均衡器的反向代理。

我得到一个零星的 502 和不少

epoll_wait() reported that client prematurely closed connection

查看 uwsgi 应用程序前面的 ALB 日志,response_processing_time 字段设置为-1。我已经测试过绕过 nginx 并直接到 ALB 与 uwsgi 应用程序对话运行良好,因此 nginx 方面的某些东西正在中断。

我查看了几十个解决方案,以下是我尝试过的主要解决方案,但没有成功

  • 尝试关闭 keepalive
  • 尝试增加保活超时
  • 确保它在 http1.1 上
  • 代理读取/连接超时增加
  • 升级到 Nginx 1.17.3
  • 增加 ulimit、somaxconn 等
  • 在 location 中设置很多标题和设置

    location @uwsgi {
     proxy_http_version 1.1;
     proxy_set_header Connection "";
     proxy_cache_key sfs$request_uri$scheme;
     proxy_pass $uwsgi_django_backend;
     proxy_set_header X-NginX-Proxy true;
     proxy_set_header Connection "";
     proxy_set_header X-Request-Start "t=${msec}000";
     proxy_set_header Host $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header X-Forwarded-Proto $scheme;
    }
    

我尝试删除 uwsgi ALB 并直接进入单个 UWSGI 应用程序。 502 消失了。显然,随着我的扩展,这不会起作用。

有没有人知道为什么 ALB 给了我不好的回应?

【问题讨论】:

    标签: amazon-web-services nginx uwsgi amazon-elb aws-application-load-balancer


    【解决方案1】:

    我通过强制上游服务使用 HTTP1.1 设法解决了这个问题

    在我的上下文中,我将环境变量 HTTP11_SOCKET 更改为 UWSGI_HTTP11_SOCKET

    【讨论】:

      猜你喜欢
      • 2016-01-17
      • 1970-01-01
      • 1970-01-01
      • 2018-05-10
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      相关资源
      最近更新 更多