Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloudflare 524 error with AJAX

I'm making an ajax request to a site behind Cloudflare. After 100 seconds, I get a 524. However I'm unable to process that 524 in my Javascript as the error page is served directly by Cloudflare and does not contain the required Access-Control-Allow-Origin headers.

I wish to retry the query in the event of getting a 524.

like image 306
Matt Joiner Avatar asked May 23 '16 02:05

Matt Joiner


People also ask

What is a 524 error?

The 524 A Timeout Occurred error is a Cloudflare-specific HTTP status code that indicates that the connection to the server has been closed due to a timeout. Depending on the context, the error might prevent you from loading a web page, signing in to an online gaming platform, or using a piece of software.

How do I fix Error 524 on WordPress?

Disable the Opcode Cache and “Purge All Caches” in W3TC. This worked for us in fixing the 524 error which used to happen frequently when making edits and saving pages in WordPress.


1 Answers

If you know that CloudFlare edge will wait for a HTTP response from the server for exactly 100 seconds, then you could just setup a timeout equal to 100 seconds on the ajax request. And retry the query after the timeout.

Alternatively, you can move this request into subdomain which is not under cloud flare proxy.


Another idea is to use a reverse proxy and adding CORS headers. In the Apache that would be

<LocationMatch "/ajax-request-used-in-js">
   ProxyPass http://example.com/ajax
   Header add "Access-Control-Allow-Origin" "*"
</LocationMatch>
like image 69
Pawel Wodzicki Avatar answered Sep 17 '22 15:09

Pawel Wodzicki