# 上游发送了无效的 Content-Encoding 头

- **ID:** `nginx/upstream-sent-invalid-content-encoding`
- **领域:** nginx
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 89%

## 根因

上游服务器返回了不受支持或格式错误的 Content-Encoding 头（例如 'gzip;q=1.0' 而非 'gzip'），导致 nginx 解压缩失败。

## 版本兼容性

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

## 解决方案

1. ```
   Fix upstream server to return valid Content-Encoding (e.g., in PHP: header('Content-Encoding: gzip'); not 'gzip;q=1.0'). For Apache backend, ensure mod_deflate uses correct header.
   ```
2. ```
   Add proxy_ignore_headers Content-Encoding; in nginx config to ignore upstream encoding and treat response as uncompressed. Example: location / { proxy_pass http://backend; proxy_ignore_headers Content-Encoding; }
   ```
3. ```
   Set proxy_set_header Accept-Encoding identity; to request uncompressed content from upstream.
   ```

## 无效尝试

- **** — This only compresses responses from nginx to client, not upstream response handling. (85% 失败率)
- **** — This prevents upstream from sending compressed responses, but if upstream still sends Content-Encoding, the error persists. (70% 失败率)
- **** — The error is about header value validity, not size. (80% 失败率)
