HTTP 状态码与网关排查速查

常用命令

curl -sS -o /dev/null -w '%{http_code}\n' https://example.com
curl -sS -I https://example.com
curl -sS -D - -o /dev/null https://example.com
curl -sS -o /dev/null -w '%{http_code} %{time_total}\n' https://example.com
curl -sS -L -o /dev/null -w '%{http_code} %{url_effective}\n' http://example.com
curl -sS -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8080/health
curl -sS -H 'Host: api.example.com' http://10.0.0.10/health
curl -sS --resolve api.example.com:443:10.0.0.10 https://api.example.com/
curl -sS -k -o /dev/null -w '%{http_code}\n' https://example.com
curl -sS -X POST -H 'Content-Type: application/json' -d '{}' -w '%{http_code}\n' https://api.example.com/v1

场景速查

目的 写法/命令 注意
继续请求 100 Continue 中间响应,不是最终结果
协议升级 101 Switching Protocols WebSocket 等升级场景
请求成功 200 OK 不代表业务逻辑成功
创建成功 201 Created 常配合 Location
成功无响应体 204 No Content 不能携带 body
永久重定向 301 Moved Permanently 缓存行为需评估
临时重定向 302 Found 客户端可能改为 GET
缓存命中 304 Not Modified 不能携带响应体
请求参数错误 400 Bad Request 查客户端请求体与字段
未认证 401 Unauthorized 缺凭证或 token 失效
已认证无权限 403 Forbidden 查 ACL、RBAC、IP 限制
资源不存在 404 Not Found 也可能是路由或代理路径错
请求被限流 429 Too Many Requests 看 Retry-After 与配额
客户端断开 499 Client Closed Request Nginx 自定义,查上游耗时
上游响应非法 502 Bad Gateway 上游崩溃、端口或协议错
服务不可用 503 Service Unavailable 无健康后端、维护或限流
上游超时 504 Gateway Timeout 上游慢或超时配置过短

易错点

相关命令

读完自测

  1. 401 与 403 的区别是什么?
  2. 499 由谁记录,常见原因是什么?
  3. 502 与 504 的区别是什么?
答案
  1. 401 表示未认证,403 表示已认证但没有访问权限。
  2. 由 Nginx 记录,表示客户端在响应前主动断开,常见于上游处理过慢。
  3. 502 是网关收到上游非法响应,504 是网关等待上游响应超时。