HTTP Status Codes Cheatsheet - HTTP Response Status Code Reference

A status code usually tells you where to look next instead of where to blame. Grouped by 1xx–5xx, each entry gives the meaning, typical cause and a fix hint, covering both REST responses returned to clients and edge-level errors such as Nginx forwarding and rate limiting. Use it to read logs, align client–server contracts, and tell 401/403 or 302/307 apart for real environments.

Reference·38 commands·Last updated 2026-07-21
httpStatus Codesnginxrest

1xx Informational 2

100 Continue
客户端应继续发送request体,常用于大上传前的预检
101 Switching Protocols
协议切换,WebSocket Upgrade握手时返回

2xx Success 5

200 OK
request成功,GET 返回资源,PUT/PATCH 返回Update结果
201 Created
资源Create成功,POST request后返回,Location 头指向新资源
202 Accepted
request已接收但未处理完,asynctask/queue处理时返回
204 No Content
成功但无response体,DELETE request常用
206 Partial Content
范围request成功,断点续传 / 视频拖拽时返回

3xx Redirection 6

301 Moved Permanently
永久redirect,SEO 权重转移,HTTP→HTTPS Jump转用
302 Found
临时redirect,不转移权重
303 See Other
redirect用 GET Get,PRG 模式(表单提交后Jump转)
304 Not Modified
资源未修改,用cache,conditionrequest(If-None-Match)命中
307 Temporary Redirect
临时redirect,保持requestmethod不变(302 可能改 POST 为 GET)
308 Permanent Redirect
永久redirect,保持requestmethod不变

4xx Client Error 17

400 Bad Request
request语法错误,如 JSON 格式不合法、缺少requiredOptions
401 Unauthorized
未认证,缺少or无效的 Token/Cookie,需登录
403 Forbidden
已认证但无Permission,如普通User访问管理interface
404 Not Found
资源不exists,URL 路径错误or资源已Delete
405 Method Not Allowed
requestmethod不允许,如对只supports GET 的interface发 POST
406 Not Acceptable
request的 Accept 头无法满足,内容协商无可用格式
408 Request Timeout
requesttimeout,客户端未在规scheduled间内发送完request
409 Conflict
资源冲突,如重复Create、concurrency修改
410 Gone
资源已永久Delete,SEO 中告知爬虫不再index(比 404 更明确)
413 Payload Too Large
request体过大,Nginx client_max_body_size 限制
415 Unsupported Media Type
不supports的 Content-Type,如interface要 JSON 却发 form
418 I'm a teapot
愚人节彩蛋(RFC 2324),茶壶不能煮咖啡
422 Unprocessable Entity
语义错误,如field格式对但值非法,Rails API 校验失败常用
426 Upgrade Required
要求客户端Upgrade协议,如force TLS or HTTP/2
429 Too Many Requests
request频率超限,限流触发(如 Nginx limit_req)
431 Request Header Fields Too Large
request头过大,如 Cookie 过多,需清理or调大头限制
451 Unavailable For Legal Reasons
因法律原因不可用,如内容审查、DMCA 下架

5xx Server Error 8

500 Internal Server Error
Service端内部错误,代码exception、空指针
501 Not Implemented
Service器不supports该requestmethod
502 Bad Gateway
网关收到上游无效response,Nginx 连不上后端or后端崩溃
503 Service Unavailable
Service不可用,过载、维护中or限流,Retry-After 头prompt重试时间
504 Gateway Timeout
网关await上游timeout,Nginx proxy_read_timeout 超限
505 HTTP Version Not Supported
不supports HTTP 协议版本
507 Insufficient Storage
存储空间不足,WebDAV Write失败时返回
511 Network Authentication Required
需Network认证,公共 WiFi 登录页场景

Typical Use Case

When an integration request returns 500, start in the 5xx section to tell app-exception from gateway failure; a 401 means you first need a Token or login, while 403 means authenticated but not authorized, so check API permissions against the 4xx semantics; on Nginx 413/429, follow the code-level fix to raise the body limit or tune rate limiting; after reading, a bare status code tells you whether to check logs, change the request, or adjust server/gateway config.

Command Examples

Show only the HTTP status code of an API

curl -s -o /dev/null -w "%{http_code}\n" https://api.example.com/users/1

用 curl 丢弃响应体只输出状态码:200 成功、404 路径不符、401 缺凭证、500 服务端异常,适合一行判断接口是否可用。

Output

200

Count 5xx responses in the Nginx access log

awk '$9 ~ /^5[0-9][0-9]$/ {print $9}' /var/log/nginx/access.log | sort | uniq -c

区别权重:502 是拿到上游无效响应(后端崩溃/拒绝连接),504 是连接成功但等待超时,据此决定查后端进程还是调高 proxy timeouts。

Output

      3 502
      5 504

Check when to retry after a 429 rate-limit

curl -i https://api.example.com/search?q=laohand

429 表示触发限流,优先读取 Retry-After 响应头(单位秒)再重试,避免继续打爆接口或被封禁。

Output

HTTP/1.1 429 Too Many Requests
Retry-After: 120

Common Pitfalls

  • Never bury business errors in 200: if the API signals failure via 200 + a body error code, clients cannot judge success from the status alone — an anti-pattern.
  • 301 gets cached by browsers/clients: clear cache or use 302 before changing the origin URL, otherwise you keep seeing the old redirect.
  • 400 vs 422 both mean a bad request: 400 is malformed syntax/structure, 422 is an invalid field value (semantic).
  • Do not confuse 502 with 503: 502 means the gateway got an invalid upstream response, 503 means the service is actively down; mixing them misleads alerting.
  • Check whether a proxy rewrote the response: Nginx default error pages can mask the real upstream status during debugging.

Tips

  • 502 vs 504: 502 means the backend returned an invalid response (crash/refused); 504 means connected but timed out.
  • 401 vs 403: 401 is 'who are you' (unauthenticated); 403 is 'you can't' (authenticated, no permission).
  • Nginx 413: raise client_max_body_size; 429: check the limit_req rate-limiting config.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us