31 codes

HTTP status codes explained

What each status code means, why it shows up in your logs and what to do about it. Written for the moment you are staring at a 502 at 2 AM, not for the exam.

The five classes

The first digit tells you who to look at. 4xx means the request itself is the problem (wrong URL, no credentials, too many requests); 5xx means the server or something in front of it failed; 3xx asks the client to go somewhere else; 2xx is success and 1xx is protocol plumbing you rarely see.

01

1xx Informational

The request was received; the server is continuing to process it.

02

2xx Success

The request was received, understood and accepted.

03

3xx Redirection

Further action is needed, usually following a new URL.

04

4xx Client error

The request is wrong, unauthorised or cannot be fulfilled as sent.

05

5xx Server error

The server failed to fulfil an apparently valid request.

Reading status codes in logs

In an nginx or Apache access log the status is the number right after the quoted request line. A quick way to see what is failing:

awk '{print $9}' access.log | sort | uniq -c | sort -rn | head

That prints a count per status code. Follow up with grep ' 502 ' access.log | tail to see the most recent failures, then paste them into Log Share so the person on call can read them with line numbers and search.

FAQ

What do the HTTP status code classes mean?

1xx informational, 2xx success, 3xx redirection, 4xx client error (the request is wrong or not allowed), 5xx server error (the server failed on a valid request).

What is the difference between 401 and 403?

401 means the server does not know who you are or your credentials failed; 403 means it knows who you are and you are not allowed.

What is the difference between 502 and 504?

Both come from a proxy or load balancer. 502: the upstream server answered incorrectly or refused the connection. 504: the upstream did not answer within the timeout.

Where do I find the real error behind a 500?

In the application or web server error log at the time of the request, ideally matched by a request id. The 500 page itself carries no detail by design.

Which status codes should a client retry?

408, 429 (after Retry-After), 502, 503 and 504 for idempotent requests, with exponential backoff. Never retry 4xx codes other than 408 and 429 without changing the request.