nginx network_error ai_generated partial

在从上游读取响应头时,上游连接被对端重置

upstream connection reset by peer while reading response header from upstream

ID: nginx/upstream-connection-reset-by-peer

其他格式: JSON · Markdown 中文 · English
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.

generic

官方文档

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream

解决方案

  1. 检查上游应用程序日志中的崩溃或超时;修复应用程序以优雅处理请求
  2. 使用proxy_next_upstream添加重试逻辑:proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
  3. 增加上游keepalive设置以减少连接变更:keepalive 32;

无效尝试

常见但无效的做法:

  1. 80% 失败

    Connection timeout only affects initial handshake, not response reading; RST occurs after connection is established.

  2. 70% 失败

    HTTP version change may affect keepalive but doesn't prevent RST from upstream.

  3. 65% 失败

    This disables keepalive but upstream may still send RST if it crashes.