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

2

6

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.

Dogvane answered 25/6, 2015 at 13:1 Comment(0)
C
10

You need a premium Cloudflare plan to customize error pages for certain response codes. From the Cloudflare dashboard (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 NGINX sends your error page to Cloudflare, Cloudflare will see the 5xx response code being sent back along with your error page and will respond with their error page instead of yours.

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;

In NGINX, before responding to Cloudflare we map the 'offending' 5xx error to a different response code. That is, instead of sending the offending 5xx response code along with our error page we change the response code to one for which Cloudflare will not override our pages. It is a good idea to map the offending 5xx error to another 5xx class error (500). Although less information is conveyed, this preserves the general meaning of the 5xx 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 - if you are getting your error page for the 504 error, then NGINX is being reached. This error would then mean, in the reverse proxy context, that NGINX passed the request on successfully but the upstream service (web server) took too long to respond.

Causerie answered 23/11, 2019 at 5:29 Comment(7)
finally someone understands, and i was thinking it was becuase of my server configs. lets say php config is set to max execution time to 3 minutes, will cloudflare wait for 3 minutes before showing their custom error page ? i dont think so.Dogvane
@AMB From my current understanding it will wait because assuming the remainder of the setup is ok, no error will be thrown for 3 minutes. At this point though the message is clear: if you use Cloudflare do not exclude it from being the source of an error somewhere in your stack. For example, maybe there is a Cloudflare to origin web server timeout setting somewhere in their configuration.Causerie
If you use the discussed NGINX config and Cloudflare is showing their page, you know there's a setting in their config because its not your page being shown => your server is not throwing, they are throwing. For this reason I suppose this setup can also assist in debugging somewhat.Causerie
it takes me a few days to find out to fix this issue until I see this comment, thank you. you saved my timeCymose
Thanks for info! Our team is currently getting frustated with this, since our REST APIs genuinely respond with 502 errors in some cases, along with payload/metadata. But all is being overrided by HTML pages from Cloudflare.Civilization
omg bro, huge thanks for that, ive been looking for so long for that workaround!Crowder
This took me a day to try to troubleshoot before finding your answer. Thank you!Noenoel
L
-2

A 504 or 502 Gateway error is actually indicative of an issue with your back end server & I would recommend contacting your hosting provider/checking your server logs.

"So my question is how can i turn off all the custom error pages from cloudflare ?" Customers on a paid plan (Pro or above) can customize error pages.

"I have double checked and my Smart-errors application in cloudflare is turned OFF , so why cloudflare is still giving their custom made page ?" SmartErrors is an entirely different feature. It is designed to only trigger when we get a 404 on a URL on your site.

Lavender answered 25/6, 2015 at 18:51 Comment(2)
Please see updated question, i have added more details as why this might have happened, and imho i dont feel right when i cant even handle my own errors unless i pay cloudflare, i know nobody is forcing me to use cloudflare but still. or maybe i am missing something , Thanks for your input.Dogvane
lets say php config is set to max execution time to 3 minutes, will cloudflare wait for 3 minutes before showing their custom error page ?Dogvane

© 2022 - 2024 — McMap. All rights reserved.