nginx protocol_error ai_generated true

上游发送了无效的状态行

upstream sent invalid status line while reading response header from upstream

ID: nginx/upstream-sent-invalid-status-line

其他格式: JSON · Markdown 中文 · English
87%修复率
84%置信度
1证据数
2024-04-05首次发现

版本兼容性

版本状态引入弃用备注
nginx/1.24.0 active
nginx/1.22.1 active

根因分析

上游服务器返回的 HTTP 状态行不符合 RFC 7230(例如缺少 HTTP 版本、状态码格式错误)。

English

Upstream server returned an HTTP status line that does not conform to RFC 7230 (e.g., missing HTTP version, malformed status code).

generic

官方文档

https://nginx.org/en/docs/http/ngx_http_upstream_module.html

解决方案

  1. Fix upstream server to return valid HTTP status line (e.g., in Python: ensure response starts with 'HTTP/1.1 200 OK\r\n'). Example using Flask: return 'OK', 200, {'Content-Type': 'text/plain'}
  2. Use a custom upstream module or script to sanitize response before nginx processes it (e.g., using lua-nginx-module: content_by_lua_block { ngx.say('OK') })
  3. Add proxy_http_version 1.0; to force HTTP/1.0 and expect simpler status line.

无效尝试

常见但无效的做法:

  1. 80% 失败

    Trailing slash affects URI normalization, not the status line format from upstream.

  2. 85% 失败

    Buffering does not affect header parsing; nginx always parses the status line.

  3. 90% 失败

    This clears response headers, not the status line itself.