opened image

    The 504 524 Gateway Timeout error is an HTTP status code that means that one server did not receive a timely response from another server it was accessing while trying to load a web page or make another browser request.

    Causes of 504 524 Gateway Timeout Errors

    In most cases, a 504 or 524 Gateway Timeout error means that the request that is sent to the server takes time than set on the server, or for example on CloudFlare. Usually these can be CRON jobs, or any other requests that require a large amount of time to execute.

    As for the 504 or 524 error that we see on Cloudflare, it says that the connection to the origin web server was successful, but the origin did not provide an HTTP response after 100 seconds, which is set by default. (This limit is set on the free plan). Enterprise customers can increase the timeout to 600 seconds.

    But in this article, you can learn how you can set up a VPS server so that by raising the limits, we can bypass the 100 second ClodFlare limit.

    If we have the ISP Manager panel installed, log in to the panel as root, select WWW-Domains, then tick the desired domain, and click Configuration Files.

    For sites on the Vesta panel, the configs can be found in the following path:

    To edit nginx /home/admin/conf/web/******.nginx.ssl.conf

    To edit apache /home/admin/conf/web/******.httpd.ssl.conf

    First, we change the Apache config by adding the Timeout directive there. This must be done before the /VirtualHost closing tag. As shown in the illustration.




    Time Out 1800


    Next, we change the nginx config by adding "location @fallback {...}" to the block as shown in the illustration:

     If the site is running in Apache mode (CGI, FastCGI), then:

    proxy_connect_timeout 1800;
    proxy_send_timeout 1800;
    proxy_read_timeout 1800;
    send_timeout 1800;


    If the site is running in PHP-FPM, then:

    fastcgi_connect_timeout 1800;
    fastcgi_send_timeout 1800;
    fastcgi_read_timeout 1800;
    send_timeout 1800;

    If such a timeout needs to be applied to all sites on this server, which is not recommended, then this construct must be added to the http block of the nginx server config. Location /etc/nginx/nginx.conf

    After that, exactly the same timeouts must be added to the PHP configuration directives max_input_time and max_execution_time. This must be done in the settings of the selected PHP version that is installed on this site.

    If you have the ISP Manager panel installed, you need to go to "Web Server Settings", then select the "PHP" item, check the desired PHP version and click "Advanced Settings"

    In the search, write max_input_time and max_execution_time and set the value to 1800. Again, it should be the same in all configs!


    If you have Vesta installed, then you need to go to the Server menu and select httpd or php-fpm


    Or edit the /etc/php.ini file from the console and set the value to 1800 for max_input_time and max_execution_time.

    Then we restart httpd and nginx, as well as php-fpm if it is installed.

    For Centos:


    systemctl restart httpd
    systemctl restart nginx
    systemctl restart php-fpm


    For Ubuntu:


    systemctl restart apache2
    systemctl restart nginx
    systemctl restart php-fpm

    We start the task or the desired script.