nginx
network_error
ai_generated
partial
在从上游读取响应头时,上游连接被对端重置
upstream connection reset by peer while reading response header from upstream
ID: nginx/upstream-connection-reset-by-peer
82%修复率
83%置信度
1证据数
2024-06-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| nginx 1.18.0 | active | — | — | — |
| nginx 1.20.2 | active | — | — | — |
| nginx 1.22.1 | active | — | — | — |
| nginx 1.24.0 | active | — | — | — |
| nginx 1.25.3 | active | — | — | — |
根因分析
上游服务器在发送完整响应之前强制关闭TCP连接(RST包),通常由应用程序崩溃或超时引起。
English
The upstream server forcibly closes the TCP connection (RST packet) before sending a complete response, often due to application crash or timeout.
官方文档
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream解决方案
-
检查上游应用程序日志中的崩溃或超时;修复应用程序以优雅处理请求
-
使用proxy_next_upstream添加重试逻辑:proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
-
增加上游keepalive设置以减少连接变更:keepalive 32;
无效尝试
常见但无效的做法:
-
80% 失败
Connection timeout only affects initial handshake, not response reading; RST occurs after connection is established.
-
70% 失败
HTTP version change may affect keepalive but doesn't prevent RST from upstream.
-
65% 失败
This disables keepalive but upstream may still send RST if it crashes.