When we access a web server or application, every HTTP request that is received by a server is responded to with an HTTP status code. HTTP status codes are 3 digit codes and are grouped into five different classes. It can be quickly identified by its first digit:
- 1xx: Informational
- 2xx: Success
- 3xx: Redirection
- 4xx: Client Error
- 5xx: Server Error
The most commonly encountered HTTP error codes are 4xx and 5xx status codes. So we will discuss about 4xx and 5xx error code and how to fix it.
1. 400 Bad Request:
It means the HTTP request that was sent to the server has invalid syntax.
Below are the few examples when a 400 Bad Request error might occur:
- The user’s cookie that is associated with the site is corrupted. Clearing the browser’s cache and cookies could solve this issue.
- Malformed request due to a faulty browser.
- Malformed request due to human error when manually forming HTTP requests (e.g. using
2. 401 Unauthorized:
It means that the user trying to access the resource has not been authenticated or incorrectly authenticated. This means that the user must provide valid credentials to be able to view the protected resource.
If a user tries to access a resource that is protected by HTTP authentication. In this case, the user will receive a 401 response code until they provide a valid username and password (one that exists in the
.htpasswd file) to the web server.
3. 403 Forbidden:
It means that the user made a valid request but the server is refusing to serve the request, due to a lack of permission to access the requested resource.
If you are getting 403 error unexpectedly, there are a few typical causes that might be causing the issue.
403 errors commonly occur when the user that is running the web server process does not have sufficient permissions to read the file that is being accessed.
If the user is getting a 403 Forbidden error, ensure that the account has sufficient permissions to read the file. Typically, this means that the other permissions of the file should be set to read.
.htaccess file can be used to deny access of certain resources to specific IP addresses or ranges, for example.
If the user is unexpectedly getting a 403 Forbidden error, ensure that it is not being caused by the
Index File Does Not Exist:
If the user is trying to access a directory that does not have a default index file, and directory listings are not enabled, the web server will return a 403 Forbidden error.
For example, if the user is trying to access
http://example.com/admin/, and there is no index file in the
admin directory on the server, a 403 status will be returned.
If you want directory listings to be enabled, you may do so in your web server configuration.
To enable it from WHM, please follow:
4. 404 Not Found:
It means that the user is able to communicate with the server but it is unable to locate the requested file or resource.
Below will be the some reasons for this error:
- Does the link that directed the user to the server resource have a typographical error in it?
- Did the user type in the wrong URL?
- Does the file exist in the correct location on the server? Was the resource moved or deleted on the server?
- Does the server configuration have the correct document root location?
- Does the user that owns the web server worker process have privileges to traverse to the directory that the requested file is in?
- Is the resource being accessed a symbolic link? If so, ensure the web server is configured to follow symbolic links.
1. 500 Internal Server Error:
It means that server cannot process the request for an unknown reason. Sometimes this code will appear when more specific 5xx errors are more appropriate.
The most common cause for this error is misconfiguration in the server (e.g. a malformed
.htaccess file) or missing packages (e.g. trying to execute a PHP file without PHP installed properly).
2. 502 Bad Gateway:
It means that the server is a gateway or proxy server and it is not receiving a valid response from the backend servers that should actually fulfill the request.
If the server in question is a reverse proxy server, like a load balancer, here are a few things to check:
- The backend servers (where the HTTP requests are being forwarded to) are healthy.
- The reverse proxy is configured properly, with the proper backends specified.
- The network connection between the backend servers and reverse proxy server is healthy. If the servers can communicate on other ports, make sure that the firewall is allowing the traffic between them.
- If the web application is configured to listen on a socket, ensure that the socket exists in the correct location and that it has the proper permissions.
3. 503 Service Unavailable:
It means that the server is overloaded or under maintenance. This error implies that the service should become available at some point.
IMP: If the server is not under maintenance, this can indicate that the server does not have enough CPU or memory resources to handle all of the incoming requests, or that the web server needs to be configured to allow more users, threads, or processes.
4. 504 Gateway Timeout:
This typically occurs in the following situations:
- The network connection between the servers is poor.
- The backend server that is fulfilling the request is too slow, due to poor performance.
- The gateway or proxy server’s timeout duration is too short.
I hope you are now very much familiar with the most common HTTP error codes and common solutions to those codes.
If you encounter any error codes that was not mentioned in this post, or if you know of other likely solutions to the ones that were described, feel free to discuss these in the below comments box.
I love cooking. Yes ! you read it right. I love cooking however I am fond of writing technical blogs too.
I work as a Cloud Developer Support Engineer II at DigitalOcean.
I hope my articles helps you to sail out from the Ocean of the technical problems. Also on other hand helps to take a deep dive into different type of technologies.
Powered by Facebook Comments