Community Tip - Fixing Error 502 / 504: Bad Gateway

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

Background
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

3 Likes
502 Bad Gateway cloudflare
Bigger timeout before 502 error from cloudflare
Change Host to new IP, can't access website
Error (502) My Site is Currently Offline
521 from cloudflare, but pausing makes site work again
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
Http://roottravelandtours.ga/
502 Gateway Error and
504 Timeout - I Give Up
Bad gateway?
I have an Error 502 when I go to my site
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
502 error on my website
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 unthost.ru
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
When I turn on Cloudflare keep getting 502 and 504 errors
Error 502 when my host is UP
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