# 上游发送了无效的状态行

- **ID:** `nginx/upstream-sent-invalid-status-line`
- **领域:** nginx
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 87%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| nginx/1.24.0 | active | — | — |
| nginx/1.22.1 | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **** — Trailing slash affects URI normalization, not the status line format from upstream. (80% 失败率)
- **** — Buffering does not affect header parsing; nginx always parses the status line. (85% 失败率)
- **** — This clears response headers, not the status line itself. (90% 失败率)
