When being able to access an internet server or application, every HTTP ask that is received with a server is taken care of immediately by having an HTTP status code. HTTP status codes are three-digit codes, and therefore are grouped into five different classes. The category of the status code could be recognized by its first digit:
- 1xx: Informational
- 2xx: Success
- 3xx: Redirection
- 4xx: Client Error
- 5xx: Server Error
This informative guide concentrates on identifying and troubleshooting probably the most generally experienced HTTP error codes, i.e. 4xx and 5xx status codes, from the system administrator’s perspective. There are lots of situations that may result in a server to reply to a request having a particular error code – we’ll cover common potential causes and solutions.
Client and Server Error Overview
Client errors, or HTTP status codes from 400 to 499, are caused by HTTP demands sent with a user client (i.e. a internet browser or any other HTTP client). Despite the fact that these kinds of errors are client-related, it’s frequently helpful to understand which error code a person is encountering to find out when the potential issue could be fixed by server configuration.
Server errors, or HTTP status codes from 500 to 599, are came back with a server when it’s conscious that a mistake has happened or perhaps is otherwise unable to process the request.
General Troubleshooting Tips
When utilizing a internet browser to check an internet server, refresh the browser after making server changes
Check server logs for more information about how exactly the server is handling the demands. For instance, web servers for example Apache or Nginx produce two files known as access.log and error.log that may be scanned for relevant information
Bear in mind that HTTP status code definitions are members of a typical that’s implemented through the application that’s serving demands. Which means that the particular status code that’s came back depends upon the way the server software handles a specific error – this informative guide should generally point you within the right direction
Now that you’ve got a higher-level knowledge of HTTP status codes, we’ll consider the generally experienced errors.
400 Bad Request
The 400 status code, or Bad Request error, means the HTTP ask that was delivered to the server has invalid syntax.
Listed here are a couple of types of whenever a 400 Bad Request error might occur:
The user’s cookie that’s connected using the website is corrupt. Clearing the browser’s cache and cookies could solve this problem
Deformed request as a result of faulty browser
Deformed request because of human error when by hand developing HTTP demands (e.g. using curl incorrectly)
The 401 status code, or perhaps an Unauthorized error, implies that the consumer attempting to connect to the resource is not authenticated or is not authenticated properly. Which means that the consumer must provide credentials so that you can see the protected resource.
A good example scenario in which a 401 Unauthorized error could be came back is that if a person attempts to access an origin that’s paid by HTTP authentication, as with this Nginx tutorial. Within this situation, the consumer will get a 401 response code until they offer a legitimate password (one which exists within the .htpasswd file) to the net server.
The 403 status code, or perhaps a Forbidden error, implies that the consumer designed a valid request however the server is refusing for everyone the request, as a result of insufficient permission to gain access to the requested resource. If you’re encountering a 403 error suddenly, there’s a couple of typical causes which are described here.
403 errors generally occur once the user that’s running the net server process doesn’t have sufficient permissions to see the file that’s being utilized.
To provide a good example of troubleshooting a 403 error, assume the next situation:
The consumer is attempting to gain access to the net server’s index file, from http://example.com/index.html
The net server worker process is a member of the world wide web-data user
Around the server, the index file is situated at /usr/share/nginx/html/index.html
When the user gets a 403 Forbidden error, be sure that the world wide web-data user has sufficient permissions to see the file. Typically, which means that another permissions from the file ought to be set to see. There are many methods to ensure this, however the following command works within this situation:
sudo chmod o=r /usr/share/nginx/html/index.html
Another potential reason for 403 errors, frequently intentionally, is using an .htaccess file. The .htaccess file may be used to deny access of certain sources to a particular IP addresses or ranges, for instance.
When the user is suddenly obtaining a 403 Forbidden error, ensure that it’s not brought on by your .htaccess settings.
Index File Doesn’t Exist
When the user is attempting to gain access to a directory without a default index file, and directory listings aren’t enabled, the net server will return a 403 Forbidden error. For instance, when the user is attempting to gain access to http://example.com/emptydir/, and there’s no index file within the emptydir directory around the server, a 403 status is going to be came back.
If you would like directory listings to become enabled, you might achieve this inside your server configuration.
404 Not Found
The 404 status code, or perhaps a Not Found error, implies that the consumer has the capacity to talk to the server but it’s not able to discover the requested file or resource.
404 errors can happen in quite a number of situations. When the user is suddenly getting a 404 Not Found error, here are a few questions you should ask while troubleshooting:
Will the link that directed the consumer for your server resource possess a typographical error inside it?
Did the consumer enter in the wrong URL?
Will the file appear in the right location around the server? Was the resource was moved or deleted around the server?
Will the server configuration possess the correct document root location?
Will the user that owns the net server worker process have rights to traverse towards the directory the requested file is within? (Hint: directories require read and execute permissions to become utilized)
May be the resource being utilized a symbolic link? If that’s the case, make sure the server is configured to follow along with symbolic links
500 Internal Server Error
The 500 status code, or Internal Server Error, implies that server cannot process the request a mystery reason. Sometimes this code can look when more specific 5xx errors tend to be more appropriate.
This most typical reason for this error is server misconfiguration (e.g. a deformed .htaccess file) or missing packages (e.g. trying to carry out a PHP file without PHP installed correctly).
502 Bad Gateway
The 502 status code, or Bad Gateway error, implies that the server is really a gateway or proxy server, which is to not get a legitimate response in the backend servers which should really match the request.
When the server under consideration is really a reverse proxy server, like a load balancer, listed here are a couple of items to check:
The backend servers (in which the HTTP demands are now being given to) are healthy
Overturn proxy is configured correctly, using the proper backends specified
The network link between the backend servers and reverse proxy server is good. When the servers can communicate on other ports, make certain the firewall is allowing the traffic together
In case your web application is configured to pay attention on the socket, be sure that the socket exists within the correct location which has got the proper permissions
The 503 status code, or Service Unavailable error, implies that the server is overloaded or under maintenance. This error signifies that the service should become available sooner or later.
When the server isn’t under maintenance, this could indicate the server doesn’t have enough CPU or memory sources to deal with all the incoming demands, or the server must be configured to permit more users, threads, or processes.
504 Gateway Timeout
The 504 status code, or Gateway Timeout error, implies that the server is really a gateway or proxy server, which is to not get an answer in the backend servers inside the permitted period of time.
- This typically happens in the next situations:
- The network link between the servers is poor
- The backend server that’s fulfilling the request is simply too slow, because of poor performance
- The gateway or proxy server’s timeout duration is simply too short
Now you understand the most typical HTTP error codes, and customary methods to individuals codes, you ought to have a great grounds for troubleshooting difficulties with your internet servers or applications.
Should you encounter any error codes which were not pointed out within this guide, or you are conscious of other likely methods to those that were described, you can discuss them within the comments.