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.

Banner in tip catalog

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, login to Cloudflare and post your question to the Community. When you post on the Community make sure to include as much of this information as possible: the specific error message you are seeing, the URLs this is happening on, screen shot of the error, and the steps to reproduce the error. Please indicate what troubleshooting steps you’ve tried in order to help us help you.

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
Error (502) My Site is Currently Offline
521 from cloudflare, but pausing makes site work again
Change Host to new IP, can't access website
Error 502 when my host is UP
Error 520 Ray ID: 508b5133f8c6dc37 • 2019-08-19 10:06:54 UTC
502 Gateway Error and
[Please help] My website is down
Error 502 Bad Gateway Error
Community Tip - All Published Tips
I have an Error 502
I have an Error 502 when I go to my site
Bad gateway?
504 Timeout - I Give Up
HTTP 520 Errors
Getting 502 errors on 50% of requests in Chrome, but works fine in Firefox
Getting error 502 many times
502 Error - Bulk Deletion
Cloudflare error 504
Error 502 Bad gateway Host Error
The web server reported a bad gateway error
Error 504 (some pages are down)
Error 522!
Getting 502 from cloudflare on all sites
Error 502 after enable cloudflare
CloudFlare error when updating a Wordpress Plugin
502 error bad gateway
Random 502 Errors
Problem with wp 5.3
Timeout Mystery
502 - Web server received an invalid response while acting as a gateway or proxy server
504 gateway timeout
Host blames Cloudflare for 504 error
Performance problems
Error 1000 - Upgraded and lost the site
How to handle 504 and 521 Errors
Balls :| - Need help with 502 error on Cloudflare's side
Wordpress Admin error 502 when editing posts
502 Errors appear and disappear frequently
Error 502 on my website
I want to hide my server's ip
Cloudflare 504 520 errors on XML Sitemap Generator
API Request Failed 2022
Wordpress Menu – Error 504?
I am getting bad server gateway error
Wordpress plugin updates fails
Cloudflare 502 and 504 error
Error 520/525/502
Error 502 Ray ID: 58058d3a387f855e • 2020-04-07 17:43:34 UTC Bad gateway
How long will cloudflare be connected to my hosting?
Cloudflare 502 errors today WPO Wordpress
Site goes down, getting 504 error in Cloudflare
Cloudflare giving 502 bad gateway since today
HTTP 504 Gateway Timeout error
After enabling Cloudflare Getting 502 Error
Constant outages over last 12 hours
Error 502 Bad Gateway Cloudflare Ray ID: 66afc2dc3cce16d1
Shared Hosting and Error 502 messages
Getaway Error 502
Cloudflare doesn't purge its cache
502 error on my website
General Server Error 502 from UK
504 time-out error after 63 secs
502 happens randomly time after time
Cloudflare DNS settings with
Cloudflare DNS settings with
Error 502 in my Site
Bad gateway error all of a sudden
CORS issue with some requests
Https, AlfaBank and Wordpress
502 error after changing name server
502 error after activate cloudflare
502 Bad Gateway nginx.-
I want to use cloudflare CDN for Managed wordpress hosting
My domain is not working & getting error 502
Cannot login ***/wp-admin. Get return error 502
Cloudflare argo tunnel gives bad gateway error
Ошибка 502
Error 504 Timeout
520 error after going to cloudflare
Cloudflare shows error 502 in my website. What is the solution for problem
Cloudflare 502 issue intermittently, Definitely automated Bot is blocked
Host error 502
How to delete AAAA records? I can't get SSL sertificate in hosting panel of my hoster for subdomain because AAAA error 502
Error 502: Bad Gateway from the host (reverse proxy NGINX)
520 and 502 errors - issue is not server side (TSOHost)
Gateway Error
How can I stop those requests its making my website, Error 504 Gateway time-out
Problem with WordPress and GTranslate (Error 504)
Facing Host issues in Helsinki Finland
Cloudflare says my host/server is down but not
My website requests encryption after 502
Firefox Intermittent 502 Errors
Web Page Showing Error 504 Always
Nodejs app gives 502 error if cloudflare proxy is turned on
Web server is returning an unknown error
I am receiving a 502 error page when I test my button on my facebook business page
Error 504 Gateway time-out
502 Bad Gateway, only when going through Cloudflare
502 error from Austria users
502 Bad Gateway, only when going through Cloudflare
Error 502 bad
504 gateway Timeout issue
Community Tip - Alle veröffentlichten Tipps
Community Tip - 公開されているすべてのヒント
502 bad gateway error
Downloaded PDFs cannot be opened after domain transfer
Error 504 sometimes from pagseguro
Error 504 sometimes from pagseguro
Email routing errors
Error updating wordpress plugins
My website always throws a 502 error when I go to it
My website always throws a 502 error when I go to it
502 Bad Gateway, only when going through Cloudflare
Apache virtual hosts and cloudflared
Easy Tunnels + Private Network + Warp macOS: No routing
When i setup cloudflare in website there are a lot of issue come how to solved that
Add TXT error - Total record size limit exceeded. Code: 83011
Не работает сервис
502 Bad Gateway
502 Bad Gateway
Merhabalar, 502
Issues with 502 on access
Subdomain sometimes down
2 or 3 errors on my site?
502 Bad Gateway only when visiting via HTTPS
Sendgrid and Bad Gateway Error
Sendgrid and Bad Gateway Error
Unstable access to site wia CloudFlare
API Request Failed: POST
API Request Failed: POST
SSL/TLS, Origin Certificates and 502 Bad Gateway
SSL/TLS, Origin Certificates and 502 Bad Gateway
SSL/TLS, Origin Certificates and 502 Bad Gateway
SSL/TLS, Origin Certificates and 502 Bad Gateway
Cloudflare And Node App Not Playing Nicely Together
Cloudflare Images API timeout when listing images
Cloudflare Tunnel with Warp Clients
Cloudflare Tunnel with Warp Clients
502 Error, Bad Gateway
Is it possible to fetch a worker endpoint in another one?
Getting occasional 504 error
Port 22: Operation timed out
Cloudflare Tunnel Unstable: with frequent disconnects
Unable to access our site from Sweden
Unable to access our site from Sweden
Trying to get Cloudflared tunnel working
Error 502 When Accessing Origin via Public Hostname Tunnel
Managed wordpress site too many redirects
Why so many 504 errors and my worker still functional?
504 errors - help finding the cause
504 errors - help finding the cause
The Speed test could not run. error 200
Getting 502: Bad Gateway errors when integrating Klaviyo
How to temporary turn off CloudFlare site for testing purpose?
DNS Error Message
Getting 504s when enabling SXG
Troubleshooting Argo Tunnel
Sudden API Request Failed: GET /api/v4/accounts/pages/projects/page=1&per_page=5 (504) error
ShipStation 502 Bad Gateway Error - Resolved
Errors 502 and 524
Simulated Google Crawl returns 15% of requests with no response
Registrar > Transfer Domains - timeout / 504
Connect WARP to a private network following Tutorial unsuccessfully
Cloudflare speed testing error 504?
While i am using dns only website working fine but while using proxied in A record my website not working
Cloudflare Tunnel without SSL is possible?
Docker tunnel is up but getting error 502
Permit HTTP traffic on non-standard port
Cannot authenticate user credentials
Always online returns 504 timeout but does not work
504 error on Cloudflare Pages deployments page
Cloudflare is not proprogating websites outside public_html
Unable to Speed Test of website
Unable to open a ticket - 504
Unable to get tunnel working
Unable to get tunnel working
Always online feature
CF Images suitable for bulk upload?
Speed Test Fails
How to block all connections other than Cloudflare on port 80 through tunnel?
Need help traversing nginx proxy to reach my cloudflare protected site (TLS end-to-end)
Cloudflare API 504 Error when Transfering in Domain
Cloudflare API 504 Error when Transfering in Domain
Seeing 520 Errors Randomly - Can't Track Down
Cloudflare caiu?
Wordpress site 502 error on google url inspection tool Site:
WAF - Create firewall inquire
How to set the default Edge Cache TTL
Does Cache Everything really cache everything?
Is my DNS configuration correct?
502 appears at irregular intervals, then after about 10 minutes +- then back to normal
Seeing status codes in wrangler tail
All sites except the main page gates an 502 error
Error 502 Bad gateway after activating "Full" encrypt mode (AWS)
Ipv6 only host can not been connected in fetch()
502 Bad Gateway API response
502 Bad Gateway API response
504 ERROR with DDoS Mitigation
Cloudflare linking issue
Need help with connection timed out 522 on Pi web server
NEWBIE IP Confusion
Shopify CDN
I was told to contact you
502 & 504 Bad gateway
-error 504
Users cant connect to my site 504 Error
Bad Gateway / Hosting Error 502
WordPress plugins
All dns records weren't found automatically
Help : Error 502 Bad gateway
502 BAD Gateway with my Dedicated Server
After upgrade to Pro my website is showing 502 Error and there is no active support to immediate fix
504 Timeout Error
502 Bad Gateway with Full SSL and redirect loop with Flexible SSL
Error 502 Bad gateway in online server
When I turn on Cloudflare keep getting 502 and 504 errors
502 Bad Gateway Error Sometimes
I cant connect my website
Not working domen. Problem with DNS