502
api
network_error
ai_generated
true
502 错误网关:上游连接被对端重置
502 Bad Gateway: upstream connection reset by peer
ID: api/http-502-bad-gateway-upstream-connection-reset
80%修复率
86%置信度
1证据数
2023-10-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| NGINX 1.24+ | active | — | — | — |
| AWS ALB 2023+ | active | — | — | — |
| HAProxy 2.8+ | active | — | — | — |
| Gunicorn 21+ | active | — | — | — |
| uWSGI 2.0+ | active | — | — | — |
根因分析
上游服务器(例如应用程序后端)在代理(例如 NGINX、ALB)尝试转发请求时突然关闭了 TCP 连接,通常是由于崩溃、超时或防火墙规则。
English
The upstream server (e.g., application backend) abruptly closed the TCP connection while the proxy (e.g., NGINX, ALB) was trying to forward the request, often due to a crash, timeout, or firewall rule.
官方文档
https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass解决方案
-
Check upstream server logs for application crashes or resource exhaustion. For example, in a Python Gunicorn setup, look for 'Worker failed to boot' or 'Out of memory'. Increase the number of workers or memory limits. Example command to add more workers: gunicorn --workers=4 --timeout=120 myapp:app
-
Verify firewall rules between proxy and upstream. On Linux, use iptables to check for dropped packets: iptables -L -n -v | grep DROP If rules are blocking, add an allow rule for the proxy IP on the upstream's port (e.g., port 8080).
无效尝试
常见但无效的做法:
-
80% 失败
The reset is immediate, not due to a slow response.
-
90% 失败
The upstream server is the root cause.