Quick answer: 504 means the backend is alive but too slow — it did not answer within the proxy's timeout. Find what is slow (usually a database query, an external API call or an exhausted PHP-FPM pool) before raising any timeout values; longer timeouts hide the disease, they do not cure it.

Overview

A 504 is a performance failure, not an outage. Something in the request path takes longer than the proxy is willing to wait. The job is to find the slow layer: app code, database, external service or resource starvation.

Before you start

  • SSH access; ability to reproduce the slow request (a specific URL helps a lot).

Step-by-step guide

  1. Measure where time goes:
    curl -o /dev/null -s -w 'ttfb: %{time_starttransfer}s total: %{time_total}s\n' https://yourdomain.com/slow-page
  2. Check resource starvation first — a saturated CPU or swapping server makes everything slow: see CPU quick diagnostics and RAM quick diagnostics.
  3. Enable and read the MySQL slow query log:
    mysql -e "SET GLOBAL slow_query_log=1; SET GLOBAL long_query_time=2;"
    sudo tail -f /var/lib/mysql/*slow*.log
    Missing indexes on large tables are the #1 cause of 504s.
  4. Look for external calls: apps waiting on third-party APIs (payment, mail, feeds) time out through no fault of the server — add caching/timeouts in the app.
  5. Only after the cause is known, align timeouts if genuinely needed (nginx fastcgi_read_timeout, PHP max_execution_time) for specific heavy endpoints like imports.

Common issues

  • Slow admin/report pages only: heavy queries — index or paginate, don't raise global timeouts.
  • 504 during backups/cron: I/O contention at fixed times — reschedule the jobs.
  • FPM pool exhausted: requests queue behind stuck workers; recycle workers and find what sticks them.

When to contact support

If timing shows the server itself is fine but the network path is slow, or performance degraded sharply without changes on your side, open a ticket with the curl -w timings and the affected URLs.

Frequently asked questions

Should I just increase the timeout values?

Not as a first step — a 504 means something is abnormally slow, usually a database query or an external API call. Find and fix the slow operation; raise timeouts only for known heavy endpoints.

How do I find which database queries cause timeouts?

Enable the MySQL slow query log with a threshold of one or two seconds, reproduce the slow page, and read the logged queries. Missing indexes on large tables are the most frequent finding.

Related articles

Need a hand? Contact Cloud2Y support →

Was this answer helpful? 0 Users Found This Useful (0 Votes)