# 上游服务器在读取响应头时发送了无效的服务器名称

- **ID:** `nginx/upstream-sent-invalid-server-name`
- **领域:** nginx
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

上游服务器响应的 HTTP 头部包含格式错误或过长的服务器名称，违反了 HTTP 规范。

## 版本兼容性

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

## 解决方案

1. ```
   Add 'proxy_ignore_headers Server;' in the location block to make nginx ignore the Server header from upstream, preventing the error.
   ```
2. ```
   Fix the upstream application to send a valid Server header (e.g., 'Server: Apache/2.4.41 (Unix)') without control characters or excessive length (> 255 characters).
   ```
3. ```
   Use a custom header filter with lua (if OpenResty) to sanitize the Server header: 'header_filter_by_lua_block { ngx.header["Server"] = nil }'
   ```

## 无效尝试

- **** — The error is about header value validity, not buffer capacity. (80% 失败率)
- **** — The root cause is the upstream server generating invalid headers; changing the target doesn't help. (90% 失败率)
- **** — proxy_buffering controls response body buffering, not header validation. (95% 失败率)
