Other 524High

Cloudflare Error 524: 5 Ways to Fix Timeout and Causes

Error 524 means Cloudflare waited 100 seconds for a response from your server but didn't receive one. This article covers key causes—from slow SQL queries to firewall blocks—and provides specific solutions for configuring web servers and applications.

Updated at March 7, 2026
15-30 minutes
Medium
FixPedia Team
Применимо к:Cloudflare (Free, Pro, Business plans)Source web server: Nginx 1.10+, Apache 2.4+, IIS 10+Applications: PHP 7.0+, Python (WSGI), Node.js (Express), Ruby (Puma/Unicorn)

What Does Error 524 Mean

Cloudflare Error 524 (Cloudflare Timeout) occurs when the Cloudflare CDN service establishes a TCP connection with your origin server but does not receive a complete HTTP response from it within 100 seconds.

The user's browser displays:

Error 524: A timeout occurred

And the response headers show:

HTTP/1.1 524
Server: cloudflare

The key point: Cloudflare generates this error before the request reaches your web server (Nginx, Apache). The problem is not with Cloudflare's infrastructure, but with your server either not responding at all or responding too slowly.

Cloudflare reverse proxy architecture diagram with a 100-second timeout

Cloudflare reverse proxy architecture diagram with a 100-second timeout

Common Causes

  1. Long-running backend request execution. A script (PHP, Python, Node.js) or a database query takes more than 100 seconds to execute.
  2. Insufficient server resources. High CPU load, lack of RAM leading to active swapping and slowing down all processes.
  3. Blocking by a firewall/WAF. A server firewall (iptables, CSF) or web application firewall (ModSecurity) drops or delays packets from Cloudflare IP addresses.
  4. Network issues. High latency or packet loss between the Cloudflare data center and your server.
  5. Timeout values set too low in configuration. proxy_read_timeout, fastcgi_read_timeout (nginx) or ProxyTimeout (Apache) values are set to less than 100 seconds, causing the server to terminate the connection prematurely.
  6. Application process hang. A PHP-FPM, Gunicorn, or Puma process is stuck waiting for an external resource (API, database) and cannot complete the request.

Solutions

Step 1: Diagnosis with curl and Cloudflare

First, confirm that the issue is specifically a Cloudflare timeout.

  1. Temporarily disable Cloudflare. In the Cloudflare dashboard for your domain, switch the cloud icon to DNS Only (gray). If the site starts working, the problem is definitely in the Cloudflare/network layer.
  2. Measure response time directly to the server. Access the server via its IP address or a domain that points directly to the server (bypassing Cloudflare).
    curl -o /dev/null -s -w "time_total: %{time_total}\n" http://SERVER_IP/problematic-path
    
    If time_total approaches or exceeds 100 seconds, the problem is with backend performance.

Step 2: Log Analysis and Resource Monitoring

Find the specific request or process causing the timeout.

  1. Web server logs. For Nginx, look for upstream timed out or gateway timeout:
    tail -f /var/log/nginx/error.log | grep -E "(upstream timed out|gateway timeout)"
    
    For Apache, check error_log.
  2. Application logs. For PHP-FPM:
    tail -f /var/log/php-fpm/error.log
    
    For Python (Gunicorn) or Node.js, check systemd logs or console output.
  3. Real-time monitoring. Install htop or glances and observe CPU, RAM load, and process count when the error occurs:
    htop
    

Step 3: Optimizing Slow Code and Queries

If the problem is in a specific script (e.g., report.php or /api/analytics):

  1. Profile the request. Use Xdebug/Blackfire for PHP, cProfile for Python, clinic.js for Node.js.
  2. Optimize database queries. For slow SQL queries, run EXPLAIN ANALYZE, add missing indexes, and rewrite complex JOINs.
  3. Implement caching. Cache results of heavy computations or database queries in Redis or Memcached. Example for PHP (Predis):
    <?php
    $redis = new Predis\Client();
    $cacheKey = 'heavy_report_data';
    $data = $redis->get($cacheKey);
    if (!$data) {
        $data = generateHeavyReport(); // Function taking >100s
        $redis->setex($cacheKey, 3600, serialize($data));
    }
    echo $data;
    
  4. Offload long-running operations to a queue. Move email sending, report generation, image processing to asynchronous tasks (RabbitMQ, Beanstalkd, Celery, Sidekiq). The web request should return quickly, while heavy work runs in the background.

Step 4: Configuring Web Server and Application Timeouts

Ensure all timeouts in the chain exceed 100 seconds, otherwise the server will terminate the request before Cloudflare does.

For Nginx (in nginx.conf or site config):

location ~ \.php$ {
    fastcgi_pass   php-fpm:9000;
    fastcgi_read_timeout 120;   # Main timeout for reading response from FastCGI
    fastcgi_connect_timeout 120; # Connection establishment timeout
}

Also check proxy_read_timeout if using a proxy.

For PHP (php.ini or .user.ini):

max_execution_time = 120    ; Max script execution time
max_input_time = 120        ; Max time for parsing input data

For Apache (in virtual host config or .htaccess):

# If using mod_proxy
ProxyTimeout 120

# If using mod_php
php_value max_execution_time 120

For Node.js (Express):

const timeout = require('connect-timeout');
app.use(timeout('120s')); // Middleware that terminates requests longer than 120s

After making changes, restart the services:

sudo systemctl restart nginx php-fpm
# or for Apache
sudo systemctl restart apache2
Examples of timeout settings in nginx, apache, and php to fix error 524

Examples of timeout settings in nginx, apache, and php to fix error 524

Step 5: Checking Network Accessibility and Firewall

Cloudflare uses fixed IP address ranges. If your firewall blocks them, the connection will be dropped.

  1. Allow Cloudflare IP addresses. Download the current lists from cloudflare.com/ips and add them to your firewall rules. Example for iptables using ipset (recommended):
    # Create set for IPv4
    ipset create cloudflare hash:ip
    # Load and add IPv4 addresses
    curl -s https://www.cloudflare.com/ips-v4 | while read ip; do ipset add cloudflare $ip; done
    # Allow traffic from Cloudflare to ports 80/443
    iptables -A INPUT -p tcp --dport 80 -m set --match-set cloudflare src -j ACCEPT
    iptables -A INPUT -p tcp --dport 443 -m set --match-set cloudflare src -j ACCEPT
    
    For firewalld or CSF, use the appropriate commands for adding networks/IPs.
  2. Check firewall logs for dropped packets from Cloudflare:
    sudo grep -i "cloudflare" /var/log/iptables.log
    sudo tail -f /var/log/fail2ban.log
    
  3. Check network quality. From your server, run ping and traceroute to any Cloudflare IP (e.g., 172.67.134.212):
    ping -c 4 172.67.134.212
    traceroute 172.67.134.212
    
    Stable ping values (< 100 ms) and no packet loss (0% packet loss) are good signs.

Prevention

  1. Regular performance audits. Enable slow_query_log in MySQL/PostgreSQL. Use APM tools (New Relic, Datadog, Scout) to identify slow endpoints.
  2. Set up response time monitoring. In Zabbix, Prometheus, or UptimeRobot, configure alerts for response times > 30 seconds.
  3. Cache at all levels. Use Cache-Control headers, cache entire pages (Varnish) or fragments (Redis, Memcached) at the application level.
  4. Implement limits on user requests. For APIs, use rate limiting (e.g., via nginx limit_req_zone) and code-level timeouts to prevent one "heavy" request from blocking a worker.
  5. Keep software up-to-date. Outdated versions of PHP, Node.js, or libraries may have memory leaks or known performance issues.
  6. Conduct load testing. Before deploying new features, test them under peak load with JMeter, k6, or Locust to assess response times.

F.A.Q.

How does error 524 differ from 504 Gateway Timeout?
Can I increase the timeout limit in Cloudflare?
The server responds in 5 seconds, but Cloudflare still shows 524. Why?
How to check if the problem is with Cloudflare and not DNS?

Hints

Check server response time directly
Analyze server and application logs
Optimize slow requests and add caching
Increase timeouts on server and in application
Allow Cloudflare IPs in firewall

Did this article help you solve the problem?

FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community