Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudflare Bad Gateway 502 error

Tags:

cloudflare

Myself and my users are often running into a Cloudflare Bad Gateway 502 error. Trying to figure out what goes wrong is hard, because Cloudflare blames the hosting company and the hosting company blames Cloudflare. A typical situation when using Cloudflare.

What I noticed is that nothing actually fails. The host receives the request and is handling the request just fine but which sometimes takes a bit longer than usual to complete. But Cloudflare can't wait and instead throws a Bad Gateway error, while the script is actually still running.

I've noticed this behavior when performing heavy back-end tasks (like generating +50 PDFs). My users notice this when they try to upload an image (which often starts a re-sizing task).

Is there a way I can configure my server so that Cloudflare knows that the request is still being processed? Or should I just ditch Cloudflare overall?

like image 497
bart Avatar asked Nov 16 '15 18:11

bart


People also ask

What causes a 502 Bad gateway error?

The HTTP 502 - bad gateway error occurs when either: The timeout of the proxy was reached prior to the request completion. If the connection proxy > server drops. When the response from the server is invalid.


2 Answers

The culprit was Railgun. After disabling Railgun (in Cloudflare's control panel) the Bad Gateway 502 errors immediately disappeared.

like image 67
bart Avatar answered Jan 05 '23 18:01

bart


I've gone through this error for quite a long time, Cloudflare support wasn't able to guide me. To solve this I tried multiple tweaks and tricks. the successful one was changing your https to HTTP in your database > wp_option. for example :

  1. https://xxxxx.com/ to http://xxxxx.com/
  2. switching your SSL setting to "full" in Cloudflare settings. this should work fine, good luck.
like image 27
TechyBrains Avatar answered Jan 05 '23 16:01

TechyBrains