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

Website 502 or 504 gateway error

The 502 and 504 errors are quite similar. The error 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. 

Generally, a HTTP 502 or 504 error 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.

There are three reasons this can occur:

  1. At the targeted IP address, the origin server was not configured to handle the requested domain name. Changing DNS records could cause this; keep in mind that DNS TTL defines how long a record is valid in the DNS cache.
  2. Server crashing, traffic spikes or lack of connectivity to the server that might cause the origin server to be overloaded or unreachable during request was made.
  3. It is either timing out or being blocked on the applications or services used at origin.

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

As you received a web response as above, you should contact your hosting provider for further troubleshooting or review your own log as if you are the server administrator.

Note that any HTTP-aware device can return 502s and 504 gateway errors. You can check on additional infrastructure between your origin and Cloudflare if your existing load balancers or local proxies in place do not notice issues in the logs of the server that handles that page.

In a very few cases, it is possible Cloudflare is displaying a 502 error page as above but in fact a different error occurred in the back-end. You should be able to verify that by generating a HAR file - How do I generate a HAR file?

On the other hand, the error page will show exactly as below as the “cloudflare” name appears at the bottom of the error message. If you do not see the “cloudflare” name, the error should come 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.

 


Comments (0)