"504 Gateway Timeout" on your website: what it means and how to fix it

A 504 means the front server waited for your site to answer and gave up. The request reached your host. Your site's program started working on it and took too long. Something is slow, not gone.

What to do, in order

  1. Find out if it is every page or one page. Load the home page, then a plain page, then the slow one. If only one page times out (a big search, an export, a checkout step), that page's code or query is the problem.
  2. If you use Cloudflare, check the timer. Cloudflare waits about 100 seconds, then shows its own 504 page. A Cloudflare-branded 504 means your host was too slow to answer. Pause Cloudflare and load the site directly to confirm.
  3. Look at the database. Most 504s on WordPress and WooCommerce are a slow database query. On a VPS, run mysqladmin processlist and look for queries running for many seconds. On shared hosting, ask support whether your account is hitting CPU or process limits.
  4. Suspect the last change. A new plugin, a backup job, or an import that runs on page load can hold the server. Rename wp-content/plugins to plugins-off over FTP. If the site answers, turn plugins back on one at a time.
  5. Read the error log. On nginx: sudo tail -50 /var/log/nginx/error.log. "upstream timed out (110: Connection timed out)" confirms the app was too slow. Raising fastcgi_read_timeout hides the symptom. Fix the slow part first.
  6. Check for traffic you did not invite. A bot crawling every search or filter URL can tie up every worker. Your access log will show hundreds of hits from one address or one user agent.

Check it yourself

Run curl -s -o /dev/null -w "%{http_code} %{time_total}s\n" https://yourdomain.com. It prints the status and how many seconds the answer took. Anything over five seconds on a plain page is worth fixing before it becomes a 504.


Want the rest of your site checked after it is back? Run a free 40-point check at tinkeraudit.com.