5xx error: how to solve server issues
HTTP 5xx codes can be caused by an error on an origin server or CDN edge servers.
Check for incidents or maintenances
If you have noticed a significant increase of 5xx codes or received multiple complaints from users, we recommend checking our Status Page for incidents or maintenance associated with the following services:
- CDN service;
- other Gcore services (if you use one of them as an origin: Storage, VPS, Dedicated Server, Cloud).
What are 5xx errors?
5xx errors can appear due to many possible reasons. In the article below we will go through the most likely reasons for the appearance of such errors and how to self-diagnose and fix them. In most cases, 5xx errors are represented by two errors: status code 502 (indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server) and status code 504 (indicates that the server, while acting as a gateway or proxy, did not get a response in time from the upstream server that it needed in order to complete the request). There are other 5xx status codes, besides 502 and 504, these are however the likeliest for you to encounter and are possible to fix on your own. In case of receiving other errors, please contact our support team.
Check your origin server
Make sure that your origin server is available.
If the origin is not responding, or it is returning an HTTP error, contact your hosting provider or server’s administrator to solve this issue.
- HTTP 504 error usually appears when an origin server fails to respond in time: the CDN edge servers wait for 5 seconds and, if an origin server is not responding, they return a 504 error. Change the settings of your origin to respond in time or make sure there is no processes slowing down the connection.
- If you are using Cloudflare or Cloudfront origin server, then make sure that you have "Change SNI Hostname" option enabled.
- If you restrict access to your origin by IP or use a DDoS Protection service, make sure that you’ve whitelisted the CDN edge servers. Use an API request below to receive the list of IP:
curl -i -X GET https://api.gcore.com/cdn/public-ip-list
Note: We constantly update this list and suggest you two solutions: creating a script to keep the origin whitelist regularly updated or using the HTTP header authorization. Find more about ACL in the article.
Check your CDN resource settings
HTTP 5xx errors can be caused by incorrect CDN resource's settings. Check the list of the most common errors below.
Incorrect origin pull protocol
Check the origin pull protocol in the resource’s settings and make sure that your origin server uses the same protocol. For more information about this feature, refer to the article.
How to check what protocol your origin supports? You can do it either via checking it directly on your server or by performing "Curl" command, which is supported on most systems by default.
To check if origin pull protocol used is correct, run the following command in the terminal (Windows) or console (macOS):
curl -H "Host: example.com" -I http(s)://10.0.0.1/file.txt
Where:
- example.com is the value of the Host header;
- http(s) is the protocol value, which depends on the protocol used by the source;
- 10.0.0.1 is the IP address of your website source;
- file.txt is any static file that is delivered via CDN.
Make note that the syntax can differ based on your operating system.
If your request returns status code 200, then that means that your origin supports the protocol you have stated in the command. If it returns 5xx status code or an SSL error, then that means that your origin doesn't support the chosen protocol. Make sure the other protocol is accessible by using the other protocol and change your Origin Pull Protocol in your CDN resource settings accordingly.
Incorrect Host header
Check the "Change Host Header" option. Make sure that the option is active, and the value is the same as the Origin Source or match with the host that you have set up on the Origin. For more information about Host Header, refer here.
How to check the Host header?
To check if the Host header used is correct, run the following command in the terminal (Windows) or console (macOS):
curl -H "Host: example.com" -I http(s)://10.0.0.1/file.txt
Where:
- example.com is the value of the Host header;
- http(s) is the protocol value, which depends on the protocol used by the source;
- 10.0.0.1 is the IP address of your website source;
- file.txt is any static file that is delivered via CDN.
If you receive a 400 Bad Request, 403 Forbidden Response, 502 Bad gateway or 504 Gateway timeout error in the response, your server is unable to process the specified Host header. In this case, follow the instructions above to manage the option.
To track the amount of 5xx errors use the Response codes statistic on the Report tab.
To receive detailed data about error responses, use our paid feature Raw Logs. Check the article to know more about Raw logs receiving set up and logs’ fields specifications.
Comments
0 comments
Please sign in to leave a comment.