Community Tip - Fixing Error 502 / 504: Bad Gateway

Try the suggestions in this Community Tip to help you fix Error 502 / Error 504: Bad Gateway / Gateway Timeout.

The 502 / 504 errors are quite similar. Generally, a HTTP 502 / 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. 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. When this happens, you will see color page with Cloudflare branding and the Error 502 Bad Gateway or Error 504 Gateway Timeout.

Quick Fix Ideas

  1. The 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. Check your origin server logs for clues as to what happened.

  3. An application or service used at your origin with is either timing out or being blocked.

  4. However, on some occasions this error is returned by Cloudflare. This might be before contacting your origin server or if we receive data that is incorrectly compressed from your origin server. In that case, the error page will look specifically like an unbranded black & white text screen.

  5. 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(s), How do I generate a HAR file?

  6. 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.

Lite Reading

Background Resources
Help Center 502 & 504 Errors
YouTube 502
YouTube 504

Research The Issue
Community 502
Community 504
Google 502
Google 504

If You Need More Help
This community of other Cloudflare users may be able to assist you, if not, login to Cloudflare and then contact Cloudflare Support. When you contact support, make sure to include as much of this information as possible: domain name, error messages, screen shots, and/or HAR file(s).

Expert Comments Appreciated
This Community Tip will remain open for input from Community experts and those familiar with this issue. We really appreciate comments that start with words like: “The three things I always try”, or “Do this first” or “In my experience”.

This is a Cloudflare Community Tip, to review other tips click here.

Çevirme…traduzir…翻译…traducir…Traduire…Übersetzen…:greyg: Translate this Tip

FXBGCT 111219

502 Bad Gateway cloudflare
Bigger timeout before 502 error from cloudflare
521 from cloudflare, but pausing makes site work again
Error (502) My Site is Currently Offline
Change Host to new IP, can't access website
Error 502 when my host is UP
CORS issue with some requests
Bad gateway error all of a sudden
Error 502 in my Site
504 time-out error after 63 secs
General Server Error 502 from UK
502 error on my website
Cloudflare doesn't purge its cache
Getaway Error 502
Shared Hosting and Error 502 messages
Constant outages over last 12 hours
After enabling Cloudflare Getting 502 Error
How long will cloudflare be connected to my hosting?
Error 502 Ray ID: 58058d3a387f855e • 2020-04-07 17:43:34 UTC Bad gateway
Error 520/525/502
Wordpress plugin updates fails
Wordpress Menu – Error 504?
502 Errors appear and disappear frequently
Balls :| - Need help with 502 error on Cloudflare's side
How to handle 504 and 521 Errors
Error 1000 - Upgraded and lost the site
Host blames Cloudflare for 504 error
Timeout Mystery
CloudFlare error when updating a Wordpress Plugin
502 error bad gateway
Error 502 after enable cloudflare
[Please help] My website is down
Problem with wp 5.3
Random 502 Errors
Error 504 (some pages are down)
Getting 502 from cloudflare on all sites
502 Error - Bulk Deletion
Error 520 Ray ID: 508b5133f8c6dc37 • 2019-08-19 10:06:54 UTC
Getting 502 errors on 50% of requests in Chrome, but works fine in Firefox
HTTP 520 Errors
502 Gateway Error and
504 Timeout - I Give Up
Bad gateway?
Error 502 bad
I have an Error 502
Community Tip - All Published Tips
Error 502 Bad Gateway Error
Not working domen. Problem with DNS
I cant connect my website
502 Bad Gateway Error Sometimes
When I turn on Cloudflare keep getting 502 and 504 errors
Error 502 Bad gateway in online server
502 Bad Gateway with Full SSL and redirect loop with Flexible SSL
After upgrade to Pro my website is showing 502 Error and there is no active support to immediate fix
502 BAD Gateway with my Dedicated Server
Help : Error 502 Bad gateway
All dns records weren't found automatically
WordPress plugins
Bad Gateway / Hosting Error 502
Users cant connect to my site 504 Error
502 & 504 Bad gateway
I was told to contact you
Shopify CDN
The web server reported a bad gateway error
Error 502 Bad gateway Host Error
I have an Error 502 when I go to my site
Merhabalar, 502
Error 504 Gateway time-out
Web server is returning an unknown error
Web Page Showing Error 504 Always
My website requests encryption after 502
Cloudflare says my host/server is down but not
Gateway Error error 502
How to delete AAAA records? I can't get SSL sertificate in hosting panel of my hoster for subdomain because AAAA
Host error 502
Cloudflare shows error 502 in my website. What is the solution for problem
502 without reasons
520 error after going to cloudflare
My domain is not working & getting error 502
I want to use cloudflare CDN for Managed wordpress hosting
502 Bad Gateway nginx.-
502 error after changing name server
Https, AlfaBank and Wordpress