nginx 作为反向代理 returns 502s 当上游服务器在 ALB 后面时
nginx as reverse proxy returns 502s when upstream server is behind an ALB
我的设置是一个连接到 nginx 框的负载均衡器,它充当位于 uwsgi 应用程序前面的负载均衡器的反向代理。
我得到一个零星的 502s 和相当多的
epoll_wait() reported that client prematurely closed connection
查看 uwsgi 应用程序前面那个的 ALB 日志,response_processing_time
字段设置为 -1
。我已经测试过绕过 nginx 并直接进入 ALB 与 uwsgi 应用程序对话运行良好,所以 nginx 端的某些东西正在中断。
我查看了数十种解决方案,以下是我尝试过但无济于事的主要解决方案
- 已尝试关闭保活
- 尝试增加保持活动超时
- 确保它在 http1.1 上
- 增加代理read/connection超时
- 升级到 Nginx 1.17.3
- 增加ulimit、somaxconn等
在location设置很多headers和settings
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 给我的回复很差吗?
我通过强制上游服务使用 HTTP1.1 设法解决了这个问题
在我的上下文中,我将环境变量 HTTP11_SOCKET
更改为 UWSGI_HTTP11_SOCKET
。
我的设置是一个连接到 nginx 框的负载均衡器,它充当位于 uwsgi 应用程序前面的负载均衡器的反向代理。
我得到一个零星的 502s 和相当多的
epoll_wait() reported that client prematurely closed connection
查看 uwsgi 应用程序前面那个的 ALB 日志,response_processing_time
字段设置为 -1
。我已经测试过绕过 nginx 并直接进入 ALB 与 uwsgi 应用程序对话运行良好,所以 nginx 端的某些东西正在中断。
我查看了数十种解决方案,以下是我尝试过但无济于事的主要解决方案
- 已尝试关闭保活
- 尝试增加保持活动超时
- 确保它在 http1.1 上
- 增加代理read/connection超时
- 升级到 Nginx 1.17.3
- 增加ulimit、somaxconn等
在location设置很多headers和settings
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 给我的回复很差吗?
我通过强制上游服务使用 HTTP1.1 设法解决了这个问题
在我的上下文中,我将环境变量 HTTP11_SOCKET
更改为 UWSGI_HTTP11_SOCKET
。