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.

2

There are 2 answers

2
damoncloudflare On

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.

5
Ders On

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.