Mondoze Knowledge Base

Search our articles or browse by category below

What should I do after seeing a 502 or 504 gateway error on my site?

Last modified: October 5, 2022
You are here:
Estimated reading time: 1 min

502 and 504 Gateway Error

The 502 and 504 errors are quite similar. They are caused by a problem connecting to an upstream server – meaning. Your server is trying to initiate a process and this fails to work as expected or times out. 

In most cases of 502 / 504 errors, back-end servers are not communicating correctly. There are three reasons this can occur:

  1. Origin Server is not configured to handle the requested domain name at the targeted IP address. Maybe caused when changing DNS records; keep in mind DNS TTL determines how long a record is valid in DNS cache.
  2. The server at the origin is overloaded or unreachable at the time the request was made. The could be due to the server crashing, traffic spikes, or lack of connectivity to the server.
  3. An application or service used at your origin with is either timing out or being blocked.

Generally, a HTTP 502 or 504 errors occurs because your origin server (e.g. your web host) is returning this code to us, and Cloudflare returns this code in turn to your visitors.

When this happens you will see an error with the Cloudflare branding:

In this case, and you should contact your hosting provider for further troubleshooting or review your own logs if you manage the server yourself.

Note that 502s and 504s can be returned by any HTTP-aware device. If you have any load balancers or local proxies in place and do not see errors in the logs of the server that handles that page, check other infrastructure between your origin and Cloudflare.

You should be able to verify that by generating a HAR file – How do I generate a HAR file?

In that case, the error page will look specifically like this:

Note that the name “cloudflare” appears at the bottom of the error message. If you do not see this, then this error is *not* coming from Cloudflare, and instead is coming from your origin server.

If you do see “cloudflare” in the error page, please run a traceroute from your machine to your domain, and point your browser to “http://example.com/cdn-cgi/trace” (replace example.com with your actual site). Then open a support ticket and copy-paste both the traceroute result and the information shown in your browser.

As mentioned previously, most of the time these error codes are actually coming from your origin web server. It might look like the screenshot below, but depending on the web server you run and the amount of customisation you have done, it may look completely different as well.

Was this article helpful?
Dislike 0
Views: 831