How to disable cloudflare custom error pages including Error 504 (Gateway time-out), While Smart Errors are already disabled?

user1642018 picture user1642018 · Jun 25, 2015 · Viewed 7.5k times · Source

I have site using cloudflare.com's free plan as reverse proxy.

I had one script which took more than 60 seconds to execute , and server threw 504 Gateway time-out , but i didnt get my web servers page, instead i got the custom page setup by cloudflare,

I have double checked and my Smart-errors application in cloudflare is turned OFF , so why cloudflare is still giving their custom made page ?

How can i switch off cloudflare's all custom pages and just use as reverse proxy.?

So my question is how can i turn off all the custom error pages from cloudflare ?

I am using nginx latest server on cent os 7. 64 bit. with php-fpm latest.


update :

This is what i got , when i go the 504 error.

Error 504 Ray ID: 1fb6a3feef7c17c8 • 2015-06-24 07:16:17 UTC
Gateway time-out
You
Browser
Working
Singapore
CloudFlare
Working
mydomain.com
Host
Error
What happened?

The web server reported a gateway time-out error.
What can I do?

Please try again in a few minutes.

CloudFlare Ray ID: 1fb6a3feef7c17c8 • Your IP: myip • Performance & security by CloudFlare

Update : as suggested by damoncloudflare, i would like to add more details.,

its a dedicated server, with linux cent os 7, 64 bit , latest nginx , php-fpm,

in nginx conf i have already specified how to handle 504 errors by

error_page  500 502 503 504             /50x.html;

How to replicate it .

code

<?php
http_response_code(504);
?>

or

<?php
sleep(61);
echo 'i am done sleeping';
?>
  • where 61 is more than max_execution_time which is 60

More details , as why originally this happened.

i was downloading huge file and the download took more than 60 seconds which is max_execution_time set in php.ini file.

So i received the cloudflare error., i would like to add there is nothing wrong with my server.

i have one more query , will i be able to disable cloudlfare 504 error and show my web servers custom page, if i upgrade from free to pro ?


update 2

i guess , now i understand the issue .,

Error 504 Gateway time-out

is triggered when server is not reachable and thats where cloudflare shows their page, obviously if server not reachable then , its not possible for server to show 504 page.

thanks for your reply.

Answer

Ders picture Ders · Nov 23, 2019

I just spent 2 hours on this! It is not the first time Cloudflare has caused me pointless pain. I am posting this answer for anyone else who may find themselves with this issue.

Cloudflare wants to make you get on a premium plan to customize certain error pages. From their website (domain name > Custom Pages tab):

500 Class Errors [...] Upgrade to Pro [...] Once you publish your custom page, Cloudflare will use your customized page instead of serving our standard 500 Class Errors page to your visitors on 502, 504, and 52x errors.

Even if your NGINX setup is correctly serving your 50x error pages, Cloudflare will see the 50x response code being sent back along with your error page, and override your page with theirs.

There exists a workaround. From the NGINX documentation on the error_page directive:

Furthermore, it is possible to change the response code to another using the “=response” syntax, for example: error_page 404 =200 /empty.gif;

Basically, we catch the 50x but instead of returning the 50x response code along with our error page we change the response code to one that Cloudflare will not override our pages for. It is a good idea to "downgrade" the error message (in specificity) to a 500 error. This conveys less information but it still fits the 50x class error.

error_page  500 503  /50x.html;
error_page  502 504  =500  /50x.html;
location = /50x.html {
    root /usr/share/nginx/html;
    internal;
}

I should add - the 504 does not mean that NGINX isn't being reached. It means, in the reverse proxy context, that NGINX passed the request on successfully, but the upstream service (FastCGI / app server, like Puma) took too long to respond.