HTTPステータスコード 解決ランブック
障害対応において「どこを見るべきか」を最短で判断するための技術リファレンス。Client, Edge, Web, App, DBの各層における切り分け手順を体系化。
⚡ 初動判断 (Verdict)
- 4xx (Client Error): クライアント側のリクエスト不備、またはWAF/LBによる遮断。サーバログには残らない場合が多い。
- 5xx (Server Error): サーバ側の処理失敗、タイムアウト、クラッシュ。App例外ログまたはミドルウェアエラーログを確認。
- Timeout / Connection Refused: ネットワーク経路、ファイアウォール、またはリソース枯渇。
🛠 障害切り分けフロー (Isolation)
左から順に確認し、エラーが発生しているレイヤー(責任境界)を特定します。
Client
🔍 curl -I -v
DNS / 4xx
Edge/CDN
🔍 WAF Log
403 / 503
LB (ALB)
🔍 Access Log
502 / 504
Web (Nginx)
🔍 error.log
500 / 502
App / DB
🔍 Exception Log
📝 観測点チェックリスト (Checklist)
| Layer | Check Point | Command Example | Next Action |
|---|---|---|---|
| 1. Frontend | Status Code & Headers | curl -I https://url |
4xx=Client, 5xx=Server |
| 2. Network | DNS & Connectivity | dig +trace, nc -zv |
Timeout=Firewall |
| 3. Web Server | Middleware Logs | tail -f /var/log/nginx/error.log |
Upstream Error=App |
| 4. Application | StackTrace / SlowQuery | grep "Error" app.log |
Fix Code / Query |
🚨 主要エラーコード対応表 (Matrix)
| Code | Typical Cause | Observe (Log) | First Fix |
|---|---|---|---|
| 400 | Bad Request (Cookie/Header Size) | Nginx log (400) | Clear Cookie / Increase Buffer |
| 401 | Unauthorized (Token Expired) | App Log (Auth) | Refresh Token |
| 403 | Forbidden (WAF / Permission) | WAF Log / File Perms | Allow IP / chmod 644 |
| 404 | Not Found (Routing) | Access Log (URI) | Check Routes / File Path |
| 429 | Too Many Requests (Rate Limit) | WAF / API Quota | Exponential Backoff |
| 500 | Internal Error (App Crash) | StackTrace / Exception | Fix Bug / Restart App |
| 502 | Bad Gateway (Upstream Down) | Nginx error.log | Start Backend / Check Socket |
| 503 | Service Unavailable (Overload) | Load Average / RAM | Scale Out / Cache |
| 504 | Gateway Timeout (Slow DB) | Slow Query Log | Optimize Query / Index |
📚 詳細リファレンス (Reference)
💡 現場の落とし穴 (Pitfalls & Tips)
Q. 502 vs 504: どっちが悪い?
A. 502は「上流が死んでいる(即死)」、504は「上流が遅い(タイムアウト)」。504ならDBロックや重い処理を疑う。
Q. 403が消えない
A. Webサーバ設定だけでなく、手前のWAF (AWS WAF, Cloudflare) がブロックしていないか確認。レスポンスヘッダの server キーを見る。