---
title: "修复 413 Request Entity Too Large，找出是哪一层拒绝了请求体"
description: "HTTP 413 Content Too Large 表示服务器认为请求体太大并拒绝了它。nginx 称之为 Request Entity Too Large，很多应用称之为 Payload Too Large。在我们的测试中，nginx 和 LogBrew API 各返回了一个 413，Content-Type 能把两者区分开。"
canonical: "https://logbrew.co/zh-Hans/errors/http-413"
last_updated: "2026-11-24"
---

# 修复 413 Request Entity Too Large，找出是哪一层拒绝了请求体

HTTP 413 Content Too Large 表示服务器认为请求体太大并拒绝了它。nginx 称之为 Request Entity Too Large，很多应用称之为 Payload Too Large。在我们的测试中，nginx 和 LogBrew API 各返回了一个 413，`Content-Type` 能把两者区分开。

如果 413 是 nginx 的 HTML 页面，就调大 `client_max_body_size`。如果是应用返回的 JSON，就发送更小的请求。

2026年11月24日 用 nginx 1.31.8、curl 8.7.1、jq 1.7.1和logbrew CLI 0.1.96 实测

作者 [Furkan Erday](https://github.com/furkanerday). Furkan Erday 是 LogBrew 的创始人，每天用 Claude Code 和 Codex 开发 LogBrew。

Canonical: https://logbrew.co/zh-Hans/errors/http-413

## 每个请求体被哪一层接收

| 发送的请求体 | nginx 放行 | API 接收 |
| --- | --- | --- |
| 2,166,027 字节，nginx 为 `1m` | 否，`413` | 否 |
| 2,166,027 字节，nginx 为 `8m` | 是 | `200` |
| 5,124,027 字节 | 是 | 否，`413` |
| 59,602 字节的 gzip | 是 | 否，`413` |
| 5,124,027 字节拆成 2 半 | 是 | 都是 `200` |

用 curl 8.7.1 发送的 5 个 OTLP 日志批次，经 nginx 1.31.8 到达本地 LogBrew API。

## 找出拒绝请求体的那一层

### 看 413 的 Content-Type

nginx 用自己的 HTML 页面响应，`Content-Type: text/html`，页面底部有它的名字。在 `client_max_body_size 1m` 下，我们 2,166,027 字节的批次收到了这个页面。

```bash
curl -sS -i http://127.0.0.1:28413/v1/logs \
  -H "x-logbrew-key: $LOGBREW_INGEST_KEY" -H 'Content-Type: application/json' \
  --data-binary @batch-2mb.json
```

输出

```text
HTTP/1.1 413 Request Entity Too Large
Server: nginx/1.31.8
Date: Tue, 24 Nov 2026 01:17:12 GMT
Content-Type: text/html
Content-Length: 183
Connection: close

<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx/1.31.8</center>
</body>
</html>
```

### 看 413 之前有没有 100 Continue

nginx 根据 `Content-Length` 拒绝了我们的请求体，没有发送 `100 Continue`。当 nginx 放行一个 5,124,027 字节的请求体时，curl 先打印 `100 Continue`，然后才是应用返回的 JSON 格式 413。两个响应都带有 `Server: nginx/1.31.8`，因为 nginx 也会给应用的响应加上这个头。

输出

```text
HTTP/1.1 100 Continue

HTTP/1.1 413 Payload Too Large
Server: nginx/1.31.8
Date: Tue, 24 Nov 2026 01:21:54 GMT
Content-Type: application/json
Content-Length: 82
Connection: keep-alive

{"message":"request body is over 4 MiB after decompression; send smaller batches"}
```

### 在 nginx 错误日志中找到那一行

nginx 拒绝请求体时，会以默认级别 `error` 写 1 行日志，里面有客户端打算发送的大小。应用返回的 413 不会在 nginx 错误日志中留下任何内容。

输出

```text
2026/11/24 04:17:12 [error] 28243#0: *6 client intended to send too large body: 2166027 bytes, client: 127.0.0.1, server: , request: "POST /v1/logs HTTP/1.1", host: "127.0.0.1:28413"
```

### 在状态码旁边记录 upstream_status

在 `http` 块的 `log_format` 中加入 `$content_length` 和 `$upstream_status`。nginx 自己拒绝请求体时，`upstream_status` 是 `-`，应用拒绝时是 `413`。

```bash
log_format body '$remote_addr "$request" $status '
                'content_length=$content_length upstream_status=$upstream_status';
access_log /var/log/nginx/body.log body;
```

输出

```text
127.0.0.1 "POST /v1/logs HTTP/1.1" 413 content_length=2166027 upstream_status=-
127.0.0.1 "POST /v1/logs HTTP/1.1" 413 content_length=5124027 upstream_status=413
```

## 修复

### 调大 nginx 的 client_max_body_size

默认值是 `1m`。在接收上传的 `http`、`server` 或 `location` 块中设置更大的值，然后运行 `nginx -s reload`。设为 `8m` 后，nginx 把同一个 2,166,027 字节的批次转给了 API，API 返回 `200`。

```bash
client_max_body_size 8m;
```

输出

```text
127.0.0.1 "POST /v1/logs HTTP/1.1" 200 content_length=2166027 upstream_status=200
```

### 不要超过应用自己的上限

nginx 不会改变它后面应用的上限。LogBrew API 在 `/v1/logs` 最多读取 4 MiB，在 `/v1/events` 最多读取 2 MiB，它的 413 会写明是哪个上限。gzip 也绕不过去。一个 59,602 字节、解压后为 5,124,027 字节的 gzip 请求体同样收到了 413。

输出

```text
{"code":"payload_too_large","error":"request body is over 2097152 bytes","limit_bytes":2097152,"next":"send under limit_bytes per request; split a batch into smaller requests","next_action":{"code":"split_batch","target":"request"}}
```

### 改为拆分批次

调大上限只会把 413 推迟到下一个大批次。我们把 5,124,027 字节、13,000 条日志的批次拆成 2 个各 6,500 条的批次，API 都接收了。LogBrew 的 JavaScript 和 Python SDK 会自动这样做，每个请求最多包含 100 个事件、256 KiB。

输出

```text
batch-5mb.json 413
batch-5mb-part1.json 200
batch-5mb-part2.json 200
```

### 把 413 日志行发送到 LogBrew

LogBrew 没有 nginx 集成，但可以接收 OTLP 日志。这条命令把访问日志中的每条 413 行和错误日志中的每条 `too large body` 行各作为 1 条日志发送。把 `LOGBREW_INGEST_KEY` 设为你项目的一个 `server` 密钥。我们本地的 LogBrew API 返回了 `{}`，说明它接收了每一行。

```bash
{ grep -E '" 413 ' /var/log/nginx/body.log; grep 'too large body' /var/log/nginx/error.log; } |
  jq -Rn '{resourceLogs: [{resource: {attributes: [{key: "service.name", value: {stringValue: "nginx"}}]}, scopeLogs: [{logRecords: [inputs | {severityText: (if test("\\[error\\]") then "ERROR" else "WARN" end), body: {stringValue: .}}]}]}]}' |
  curl -sS https://api.logbrew.co/v1/logs -H "x-logbrew-key: $LOGBREW_INGEST_KEY" \
    -H 'Content-Type: application/json' --data-binary @-
```

输出

```text
{}
```

### 用 LogBrew CLI 找到它们

错误日志行的级别是 `error`，每条 413 行的级别是 `warning`。搜索 `upstream_status=-`，只列出被 nginx 拒绝的请求体。

```bash
logbrew read logs --project "<project_id>" --service nginx --severity error --since 1h
logbrew read logs --project "<project_id>" --service nginx --search 'upstream_status=-' --since 1h
```

输出

```text
Logs (1)
- error 2026/11/24 04:17:12 [error] 28243#0: *6 client intended to send too large body: 2166027 bytes, client: 127.0.0.1, server: , request: "POST /v1/logs HTTP/1.1", host: "127.0.0.1:28413" service=nginx trace=ec27d913a85bdbfe8252a31cf276fccf [unversioned / production]
Logs (1)
- warning 127.0.0.1 "POST /v1/logs HTTP/1.1" 413 content_length=2166027 upstream_status=- service=nginx trace=b2f9eee905fea8254bac86a398fd8f39 [unversioned / production]
```

## 我们测试时看到的结果

我们在 macOS 27.2 上运行 nginx 1.31.8，监听 `127.0.0.1:28413`，后面是本地的 LogBrew API。curl 8.7.1 用 `--data-binary` 向 `/v1/logs` 发送了 5 个 OTLP 日志批次。

在 `client_max_body_size 1m` 下，nginx 拒绝了 2,166,027 字节的批次，API 根本没有收到它。设为 `8m` 后，API 拒绝了每个超过 4 MiB 的批次，包括 gzip 的那个，并接收了拆分后的 2 半。

|  | `$status` | `$upstream_status` |
| --- | --- | --- |
| 2,166,027 字节，nginx 为 `1m` | `413` | `-` |
| 2,166,027 字节，nginx 为 `8m` | `200` | `200` |
| 5,124,027 字节 | `413` | `413` |
| 59,602 字节的 gzip | `413` | `413` |
| 5,124,027 字节拆成 2 半 | `200` | `200` |

## 为什么 413 有 3 个名字

RFC 9110 第 15.5.14 节把 413 命名为 `Content Too Large`。RFC 7231 称它为 `Payload Too Large`，RFC 2616 称它为 `Request Entity Too Large`。nginx 1.31.8 仍然发送最旧的名字，LogBrew API 发送 `Payload Too Large`，所以名字并不能说明是谁返回的。

nginx 文档中 `ngx_http_core_module` 给出的 `client_max_body_size` 默认值是 `1m`，设为 `0` 会关闭这项检查。nginx 在读取我们的请求体之前就用 `Content-Length` 和上限做了比较，所以应用从未收到被拒绝的请求。

1. 客户端发送 `Content-Length`
2. nginx 检查 `client_max_body_size`
3. 应用按自己的上限读取请求体

## LogBrew 记录了什么

LogBrew 把我们发送的每一行存为 `nginx` 服务的 1 条日志。它把整行作为消息保存，不会拆成字段，所以请搜索文本。

控制台、CLI 和 MCP 服务器读取这些日志的方式，和读取其他 LogBrew 日志一样。

- `nginx`
  - `level`: `error`
  - 消息: `… client intended to send too large body: 2166027 bytes …`
  - `trace`: `ec27d913a85bdbfe8252a31cf276fccf`

## 常见问题

### 413 Content Too Large 是什么意思？

服务器拒绝了请求，因为请求体超过了它接受的大小。RFC 9110 把状态码 413 命名为 `Content Too Large`。

### 413 Request Entity Too Large 和 413 Payload Too Large 有什么区别？

没有区别。两者都是同一个状态码的旧名字。nginx 发送 `Request Entity Too Large`，很多应用发送 `Payload Too Large`。

### 如何修复 nginx 的 413 Request Entity Too Large？

在接收请求的块中调大 `client_max_body_size`，例如设为 `8m`，然后运行 `nginx -s reload`。默认值是 `1m`。

### 为什么调大 client_max_body_size 后还是 413？

你的应用有自己的上限。如果 413 是 JSON 而不是 nginx 的 HTML 页面，说明是应用拒绝了请求体。发送更小的请求，或调大应用的上限。

### gzip 能解决 413 错误吗？

如果应用按解压后的字节数计算，就不能。我们 59,602 字节的 gzip 请求体通过了 nginx，但 LogBrew API 把它解压成 5,124,027 字节后返回了 413。

## 在 1 个地方搜索每条 413 行

把 nginx 日志行作为 OTLP 日志发送到 LogBrew，然后在控制台、CLI 或你的 AI 智能体中搜索。免费额度充足，无需绑卡。

[免费开始](https://logbrew.co/zh-Hans)

## 参考来源

- [RFC 9110, HTTP Semantics, 15.5.14 413 Content Too Large](https://www.rfc-editor.org/rfc/rfc9110#section-15.5.14)
- [LogBrew docs, Send OpenTelemetry data to LogBrew with OTLP](https://docs.logbrew.co/guides/opentelemetry)
- [LogBrewCo/sdk, JavaScript SDK, Queue Bounds](https://github.com/LogBrewCo/sdk/blob/main/js/logbrew-js/README.md#queue-bounds)

## 更多错误修复

- [修复隐藏了消息、文件和行号的脚本错误](https://logbrew.co/zh-Hans/errors/script-error)
- [修复 Failed to fetch 错误，分清它的 3 种原因](https://logbrew.co/zh-Hans/errors/failed-to-fetch)
- [从消息入手修复 Kotlin 和 Android 中的 java.lang.NullPointerException](https://logbrew.co/zh-Hans/errors/nullpointerexception)
- [从完整消息和你自己的代码行入手修复 Minified React error #418 和 #185](https://logbrew.co/zh-Hans/errors/minified-react-error)
- [在浏览器和 Node.js 中修复 Cannot use import statement outside a module](https://logbrew.co/zh-Hans/errors/cannot-use-import-statement-outside-a-module)
- [修复 AxiosError Network Error，找出你遇到的是 3 种原因中的哪一种](https://logbrew.co/zh-Hans/errors/axios-network-error)
- [修复 HTTP 499 错误，找出是谁先停止了等待](https://logbrew.co/zh-Hans/errors/http-499)
- [我们复现过的错误，以及每个错误的修复方法](https://logbrew.co/zh-Hans/errors)
