# HTTP 408 请求超时

**HTTP 408 请求超时**是一种客户端错误响应状态码，定义于 RFC 9110 第 15.5.9 节，服务器在准备等待的时间内未收到完整的请求消息时便会发送该状态码。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> 该状态码告知客户端：服务器已放弃等待该请求，并且实际上打算关闭连接，而不是继续将其保持打开。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/408)</sup>

| 关键事实 | 详情 |
|---|---|
| 状态类别 | 4xx（客户端错误）；服务器在等待客户端完成发送请求时超时<sup>[3](https://lens.net/compare/408-vs-504/)</sup> |
| 正式定义 | “服务器在准备等待的时间内未收到完整的请求消息”（RFC 9110，§15.5.9）<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 连接处理 | 根据 MDN 的指引，服务器应发送 `Connection: close` 头字段，因为 408 实际上意味着服务器打算关闭连接而非继续等待<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/408)</sup> |
| 空闲连接 | 某些服务器即使客户端此前从未发送过任何请求，也会在空闲连接上发送 408<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/408)</sup> |
| 重试行为 | 如果客户端有尚未完成的请求正在传输中，它可以重复该请求；在 HTTP/1.1 中，由于请求定界信息已丢失，需使用新连接<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 与 504 的区别 | 504 网关超时是 5xx 状态码，表示代理放弃等待上游服务器；408 则表示服务器本身放弃等待客户端<sup>[3](https://lens.net/compare/408-vs-504/)</sup> |
| 典型服务器默认值 | 如果客户端在 `client_header_timeout` 或 `client_body_timeout` 内未发送任何内容，nginx 会以 408 终止请求，这两项默认均为 60 秒<sup>[4](https://nginx.org/en/docs/http/ngx_http_core_module.html)</sup> |

## 该状态码的含义

408 状态码针对的是一种特定的故障模式：请求从未完整到达。客户端打开连接、开始发送请求，然后停滞不前——原因可能是网络缓慢、客户端过载，或者请求体（例如大文件上传）被中断。服务器的配置等待期届满后，便以 408 响应，而不是无限期地保持连接。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup><sup> • </sup><sup>[5](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/4xx-client-error/error-408/)</sup>

由于服务器已决定停止等待，该响应通常表示连接就此结束。MDN 的指引是服务器应在 408 响应中发送 `Connection: close` 头字段。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/408)</sup> 某些服务器则更进一步，直接关闭连接，根本不发送任何 408 消息。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/408)</sup>

**重试请求。** RFC 9110 允许有尚未完成请求正在传输中的客户端重复该请求。如果当前连接不可用——在 HTTP/1.1 中由于请求定界信息丢失便会如此——则重试需通过新连接进行。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> 一份对比指南指出，408 只有在修复根本原因之后重试才是安全的；这与 504 不同，后者通过退避重试可能成功，因为后端或许会恢复。<sup>[3](https://lens.net/compare/408-vs-504/)</sup>

## 空闲连接与预连接

408 并不总是跟在部分请求之后。某些服务器即使客户端此前从未发送过任何请求，也会在空闲连接上发送 408，以此关闭它们不再希望保持打开的连接。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/408)</sup><sup> • </sup><sup>[6](https://-status.org/docs/408/?perspective=server)</sup>

这种做法变得更加普遍，因为 Chrome 和 Firefox 等浏览器使用 HTTP 预连接机制来加速浏览，在请求就绪之前便推测性地打开连接。将这些未使用的连接超时断开的服务器，可能会对最终到来的请求以 408 作答。<sup>[2](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/408)</sup> 复用持久连接时也会出现类似的竞态：如果客户端在服务器空闲超时到期的瞬间通过持久连接发出另一个请求，它可能收到 408 或连接重置，而不是有效回复，因此边缘层通常配置的持久连接超时会长于源服务器。<sup>[7](https://tatus.com/408/)</sup>

## 常见原因

[Cloudflare](https://www.edgepedia.org/zh/cloudflare) 的文档列出了典型场景：网络连接缓慢、服务器过载，以及客户端完成请求时的延迟。<sup>[5](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/4xx-client-error/error-408/)</sup> 当客户端上传数据迟缓、移动应用的连接反复断开，或者损坏的请求送达头部后在发送主体前停滞时，日志中就会出现 408；慢速读取 DDoS 攻击也会产生该状态码，因为攻击者以极慢的速度传输，以占用服务器资源。<sup>[3](https://lens.net/compare/408-vs-504/)</sup>

## 服务器如何实现

服务器软件各自设定超时阈值，而 408 响应是报告某一阈值被触发时的标准方式。

- **nginx** 定义了两条相关指令。`client_header_timeout`（默认 60 秒）在客户端未及时传输完整头部时以 408 终止请求，`client_body_timeout`（默认 60 秒）对主体做同样处理；主体超时仅适用于两次连续读取操作之间的间隔，而不适用于整个主体的传输。<sup>[4](https://nginx.org/en/docs/http/ngx_http_core_module.html)</sup>
- **Node.js** 在其服务器超时到期时以状态码 408 响应，不将请求转发给请求监听器，然后关闭连接。<sup>[8](https://nodejs.org/download/release/latest-v16.x/docs/api/http.html)</sup>
- **Cloudflare** 如果公共客户端对其网络的请求超过某些内部定义的超时，可能会返回 408；这些超时是作为保护措施配置的，无法更改。在由 Cloudflare 提供支持的站点上，408 通常是从源站代理而来的，因此源服务器的超时设置和负载是首先要检查的内容。<sup>[5](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/4xx-client-error/error-408/)</sup>

## 408 与 504 网关超时

这两个超时状态码位于同一网络跳的两端，混淆它们会导致客户端重试缺陷、错误的缓存信号和误导性的监控数据。<sup>[9](https://errorlookup.com/compare/408-vs-504/)</sup>

- **408（4xx，客户端错误）：** 服务器在等待客户端发送请求数据，而客户端太慢或让连接处于空闲状态。问题出在服务器的上游，即客户端或其网络连接。<sup>[3](https://lens.net/compare/408-vs-504/)</sup>
- **504（5xx，服务器错误）：** 网关或代理（如 nginx、应用负载均衡器或 Cloudflare）将请求转发给上游服务器，并在配置的等待时间内未收到响应。请求已完整传输；是后端太慢。<sup>[3](https://lens.net/compare/408-vs-504/)</sup><sup> • </sup><sup>[10](https://www.httpstatus.com/504/)</sup>

这一区分对自动化客户端很重要：按 504 分支处理的 API 客户端期望的是网关超时语义，而将 408 视为服务器端故障会把排查引向错误方向。<sup>[9](https://errorlookup.com/compare/408-vs-504/)</sup>

## 历史与规范状态

该状态码自最初的 HTTP/1.1 规范——1999 年 6 月的 RFC 2616——起便已存在，该规范在其状态码列表中列有 408 请求超时。<sup>[11](https://www.rfc-editor.org/info/rfc2616/)</sup> 2014 年 6 月发布的 RFC 7231 沿用了这一定义。<sup>[12](https://www.rfc-editor.org/rfc/rfc7231.html)</sup> 当前定义见于 2022 年 6 月发布的 RFC 9110《HTTP 语义》，该规范废止了 RFC 7231 并整合了状态码定义。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

## References

1. [RFC 9110: HTTP Semantics, §15.5.9 408 Request Timeout, IETF](https://www.rfc-editor.org/rfc/rfc9110.html)
2. [408 Request Timeout, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/408)
3. [HTTP 408 Request Timeout vs 504 Gateway Timeout, HTTPLens](https://lens.net/compare/408-vs-504/)
4. [Module ngx_http_core_module, nginx documentation](https://nginx.org/en/docs/http/ngx_http_core_module.html)
5. [Error 408, Cloudflare Support docs](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/4xx-client-error/error-408/)
6. [408 Request Timeout, HTTP Status Codes Reference](https://-status.org/docs/408/?perspective=server)
7. [408 Request Timeout, HttpStatus.com](https://tatus.com/408/)
8. [HTTP, Node.js v16.20.2 Documentation](https://nodejs.org/download/release/latest-v16.x/docs/api/http.html)
9. [408 vs 504 – request timeout vs gateway timeout | errorlookup](https://errorlookup.com/compare/408-vs-504/)
10. [504 Gateway Timeout, HttpStatus.com](https://www.httpstatus.com/504/)
11. [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1, RFC Editor](https://www.rfc-editor.org/info/rfc2616/)
12. [RFC 7231: HTTP/1.1 Semantics and Content, RFC Editor](https://www.rfc-editor.org/rfc/rfc7231.html)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › HTTP and web communication protocols › HTTP status codes

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/http-408-request-timeout

English original: https://www.edgepedia.org/http-408-request-timeout
