# 上游发送的标头过大，同时从上游读取响应标头，客户端：10.0.0.1，服务器：example.com，上游：“http://127.0.0.1:8080”

- **ID:** `nginx/proxy-buffer-size-too-small`
- **领域:** nginx
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

上游服务器的响应标头超过默认的 proxy_buffer_size（4KB），导致 nginx 拒绝响应并返回 502 错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| nginx/1.18.0 | active | — | — |
| nginx/1.20.0 | active | — | — |
| nginx/1.24.0 | active | — | — |
| nginx/1.26.0 | active | — | — |

## 解决方案

1. ```
   在 location 或 server 块中将 proxy_buffer_size 增加到 8K 或更大（例如 16K）：`proxy_buffer_size 16k;`
   ```
2. ```
   同时增加 proxy_buffers 以保持一致：`proxy_buffers 8 16k;`
   ```
3. ```
   如果大标头是由于过多 cookie 引起的，请考虑在应用程序级别使用自定义标头压缩或减少 cookie 大小作为长期修复。
   ```

## 无效尝试

- **** — proxy_buffers controls the number and size of buffers for the response body, not the initial header buffer. (70% 失败率)
- **** — proxy_buffering off affects body buffering, not header buffering; the header buffer size is always limited by proxy_buffer_size. (60% 失败率)
- **** — While this can fix the symptom, it requires application changes that may break features like session management or authentication. (40% 失败率)
