[This is all you need to remember] A quick review of HTTP status code errors

Introduction

Nice to meet you all!

This is my first time writing a blog. I'm Mikoto, a graduate of the System Solutions Department in 2024.
I couldn't think of a nickname, so my mother gave one to me.

would like to mainly explain about 4XX and 5XX, which are called error codes and which I feel are important in my work

↑The error code is 401 in the image above!

To explain, we will look at the status codes from sample access logs recorded on the server, but if you are unfamiliar with this, I hope you will just take a quick look at it to understand that this is what we normally look at to analyze access

By the way, if you are interested in access logs, please refer to this!
[Apache] A simple explanation of how to read access logs! *Updated in 2024
[nginx] Explaining how to read, configure, and locate access logs

 

What is a status code anyway?

A status code is a three-digit number that a web server returns in response to an HTTP request , and you can use this number to check the status of the request you sent!
You can check it in the developer tools (similar to the inspector in Chrome), so take a quick look if you'd like.


↑The part in the red frame is the status code!

Status codes Informational (1XX), Success (2XX), Redirection (3XX), Client Error (4XX), and Server Error (5XX) , which gives a clear understanding of whether the access was successful or, if not, what the problem was.

Two types of error codes

4XX - Client Error

Status codes starting with 4 mainly indicate a problem on the client (user) side, and are seen when the server cannot process the request due to an error in the request content or access denial

For example, I often see something like this:

▼400 Bad Request:

127.0.0.1 - - [25/Dec/2023:14:25:00 +0900] "GET /api/data?date=2023-12-33 HTTP/1.1" 400 172 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"

This is because the request format sent by the client was incorrect, resulting in a 400 error.
For example, in the example above, the client entered an invalid date (December 23, 2023) for '/api/data', which caused a 400 error.

▼401 Unauthorized:

127.0.0.1 - - [25/Dec/2023:13:15:00 +0900] "POST /login HTTP/1.1" 401 187 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"

This error indicates that the client is not providing the correct authentication credentials.
In the example above, we made a POST request to /login and received a 401 error, which likely indicates that the client did not submit the correct username, password, etc.

▼403 Forbidden:

127.0.0.1 - - [25/Dec/2023:13:20:00 +0900] "GET /admin/settings HTTP/1.1" 403 249 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30"

Forbidden is an English word meaning "prohibited," and as the name suggests, it is an error code that can be displayed when a request is sent to a path that only limited users can access.
In the example error, we can see that an unauthorized client sent a GET request to /admin/settings, but a 403 error was returned.

▼404 Not Found:

127.0.0.1 - - [25/Dec/2023:13:25:00 +0900] "GET /about-us HTTP/1.1" 404 210 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1"

This 404 error can be returned when the server cannot find the requested resource, which can happen for a number of reasons:

  1. The user mistyped the URL
  2. The specified page was old and no longer exists
  3. The correct URL was not set due to a server misconfiguration
  4. The resource has been temporarily moved or deleted

5XX - Server Error

Status codes beginning with 5 indicate a problem on the server side

For example, there are the following:

▼500 Internal Server Error:

127.0.0.1 - - [25/Dec/2023:14:00:00 +0900] "GET /dashboard HTTP/1.1" 500 215 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"

This error code is returned when an internal error occurs on the server and the request cannot be processed

If you encounter this error, you can find the cause by reviewing the most recent edits you made to the server settings!
Also, if the error occurred after making some configuration changes, you can resolve the issue by restoring to a backup you made beforehand!

▼503 Service Unavailable:

127.0.0.1 - - [25/Dec/2023:14:15:00 +0900] "GET /reports HTTP/1.1" 503 212 "-" "Mozilla/5.0 (iPad; CPU OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Mobile/15E148 Safari/604.1"

The server is temporarily unable to process the request, possibly due to maintenance or overload

For example, if there is a sudden increase in access, the server may not be able to handle it and may return a 503 error!

▼504 Gateway Timeout:

127.0.0.1 - - [25/Dec/2023:14:20:00 +0900] "GET /video/stream HTTP/1.1" 504 160 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36"

This occurs when the server load becomes too high for some reason, causing the gateway/proxy server to exceed the specified time (timeout value) while waiting for a response from the upstream server. This
makes it difficult to respond to user requests within the time limit.

Also, restarting the middleware and temporarily resetting the connection may fix the problem, but to prevent it from recurring, you need to investigate the reason why the processing is taking so long.
(Extending the timeout value is one solution, but I've never seen it work that way during business hours.)

Examples of causes include the following:

  1. It's stuck doing some heavy processing
  2. Performing large-scale database operations that consume a lot of resources
  3. There is a network problem
  4. Something is wrong with the upstream server

Trivia

▼418 I'm a teapot:

Are you familiar with this 418 error?

This status code was defined on April Fool's Day about 20 years ago, and
it causes an error when you try to pour coffee into a teapot and it is rejected.

In fact, it is not an HTTP communication status code, but rather exists as a status code for HTCPCP (Hyper Text Coffee Pot Control Protocol) communication, and even the verification tool will show the status as 418

If you're interested, please check it out
here Also, like 418, HTCPCP is also an April Fool's joke, so be sure to check it out!

summary

That concludes our introduction to the error codes among status codes!
There are also other error codes, such as 499, that are output by specific middleware, so if you're interested, be sure to check them out!

Now that I'm in my first year as an infrastructure engineer, I encounter status codes quite often, so I recommend studying them if you're interested (although I started without knowing anything about them)

Thank you for watching!

Reference:
[List of frequently seen ones explained] What is an HTTP status code? Detailed explanation by code number
HTTP status code list and detailed guide
HTTP response status code
What is HTTP status code 418?

If you found this article useful, please click [Like]!
6
Loading...
6 votes, average: 1.00 / 16
926
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author

Mikoto

I'm an infrastructure engineer who joined the company in April 2024 after graduating from a liberal arts faculty.
I couldn't think of a nickname, so I chose one my mother often uses.
Shoebills are so cute, aren't they?