# HTTP 状态码总览

URL: https://caijiao.org/reference/http/status-codes
Source: docs/reference/http/status-codes.md
Description: HTTP 状态码 Reference，按 1xx、2xx、3xx、4xx、5xx 整理常见状态码含义、使用场景、前端处理和 SEO 注意事项。

HTTP 状态码表示一次请求的处理结果。调试接口、排查 Nginx、分析 Search Console 抓取问题时，先确认真实状态码，再判断页面内容或前端逻辑。

## 分类

| 范围 | 含义 | 常见状态码 |
| --- | --- | --- |
| `100-199` | 信息响应 | `100`、`101`、`103` |
| `200-299` | 成功响应 | `200`、`201`、`204`、`206` |
| `300-399` | 重定向 | `301`、`302`、`304`、`307`、`308` |
| `400-499` | 客户端错误 | `400`、`401`、`403`、`404`、`405`、`409`、`410`、`422`、`429` |
| `500-599` | 服务端错误 | `500`、`501`、`502`、`503`、`504` |

## 高频状态码

| 状态码 | 含义 | 常见场景 |
| --- | --- | --- |
| `200 OK` | 请求成功 | 普通页面、接口成功返回 |
| `201 Created` | 已创建资源 | 创建用户、提交订单、上传成功 |
| `204 No Content` | 成功但没有响应体 | 删除成功、保存成功但无需返回内容 |
| `301 Moved Permanently` | 永久重定向 | URL 永久迁移、HTTP 跳 HTTPS |
| `302 Found` | 临时重定向 | 活动页、A/B 测试、登录跳转 |
| `304 Not Modified` | 资源未修改 | 浏览器缓存验证命中 |
| `400 Bad Request` | 请求格式错误 | 参数缺失、JSON 格式错误 |
| `401 Unauthorized` | 未认证 | 未登录、Token 缺失或失效 |
| `403 Forbidden` | 已认证但无权限 | 权限不足、IP 被拒绝 |
| `404 Not Found` | 资源不存在 | 页面删除、接口路径错误 |
| `429 Too Many Requests` | 请求过多 | 限流、频率控制 |
| `500 Internal Server Error` | 服务端内部错误 | 代码异常、未捕获错误 |
| `502 Bad Gateway` | 网关错误 | Nginx 代理上游失败 |
| `503 Service Unavailable` | 服务不可用 | 维护、过载、服务未启动 |
| `504 Gateway Timeout` | 网关超时 | 上游响应太慢 |

## 前端处理示例

```js
const response = await fetch("/api/posts");

if (!response.ok) {
  throw new Error(`HTTP ${response.status}`);
}

const data = await response.json();
```

## SEO 注意事项

- 永久迁移优先使用 `301` 或 `308`，并让旧 URL 直接跳到最终目标。
- 已删除且没有替代页面时返回真实 `404` 或 `410`，不要返回 200 的错误页面。
- 临时活动、A/B 测试更适合 `302`，不要误用 `301`。

## 相关内容

- [HTTP Status 查询工具](/tool/http-status-lookup)
- [HTTP Reference](/reference/http/)
- [HTTP Redirect](/reference/http/redirect)
- [Fetch 如何处理 HTTP 错误](/how-to/javascript/handle-fetch-error)
- [301 和 302 重定向怎么选](/how-to/seo-website/301-vs-302)
- [Google Search Central](/google-search-central/)
- [MDN HTTP response status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status)
