Home › Knowledgebase › KB-1213

How to fix 504 gateway timeout error

Summary

This guide helps you troubleshoot and resolve: How to fix 504 gateway timeout error. Follow the steps below to fix the issue.

Quick Tip: Need immediate assistance? 💻 Open a Ticket

Common Causes

A 504 Gateway Timeout error means that a server acting as a gateway or proxy did not receive a timely response from an upstream server. This typically happens when your website is experiencing high traffic, a backend process is hanging, PHP-FPM has timed out, or server resources have been exhausted. Unlike DNS resolution errors, a 504 error occurs after a connection has already been established, meaning your domain is resolving correctly but the upstream server is not responding within the expected timeframe.

Remember — If you host with us, you don't need to do this yourself — just Open a Ticket and our team will get it sorted.

Quick Fix Steps

  1. Refresh your browser page to see if the error clears.
  2. Clear your browser cache and cookies.
  3. Try accessing your website from a different network or mobile device.
  4. Check if other websites on the same hosting account are also affected.

Detailed Instructions

1. Check Server Resources

A 504 error often occurs when your server has run out of memory or CPU capacity, causing upstream processes to time out before they can respond.

  1. Log in to your hosting control panel (such as cPanel, Plesk, or your provider's custom dashboard).
  2. Navigate to the Resource Usage, CPU and Concurrent Connection Usage, or Statistics section.
  3. Review the graphs for CPU, memory, and entry processes.
  4. If you see sustained spikes at or near 100%, your plan may be underpowered for your current traffic.
  5. Consider upgrading your hosting plan or optimising your website to reduce resource consumption.
On shared hosting, resource throttling is common during traffic peaks. If your site regularly hits limits, moving to a VPS or dedicated environment may provide more consistent performance.

2. Review Application Error Logs

Application-level logs often reveal the specific process causing the timeout, such as a hanging PHP script, a slow database query, or a PHP-FPM process that has exceeded its execution limit.

  1. Log in to your hosting control panel.
  2. Navigate to Metrics > Errors (cPanel) or the equivalent Logs section in your dashboard.
  3. Look for entries containing 504, gateway timeout, upstream timed out, or PHP-FPM.
  4. If you use WordPress, enable debugging by adding the following lines to your wp-config.php file:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
  1. Reproduce the error on your website, then check the wp-content/debug.log file via FTP or File Manager for fatal errors or slow query warnings.
Before making configuration changes on a production website, test them in a staging environment first. Changes to timeout settings or server configuration can mask underlying performance issues or cause unexpected downtime.

3. Review Third-Party Integrations and Plugins

Slow or hanging API calls to external services can cause your server to wait too long for a response, triggering a 504 error. This is common during form submissions, checkout processes, or shipping calculator lookups.

  1. Log in to your website's administration area (for example, WordPress wp-admin).
  2. Go to Plugins > Installed Plugins.
  3. Deactivate any recently installed or updated plugins, especially those that connect to external APIs, payment gateways, or shipping calculators.
  4. Refresh your website to check if the error disappears.
  5. Reactivate plugins one at a time to identify the problematic integration.
Always create a full website backup before deactivating or removing plugins, particularly on live production sites.

4. Adjust Server Timeout Settings (VPS or Dedicated Only)

If your backend scripts take longer than the default limit to execute, the gateway may close the connection prematurely. These steps apply only if you manage your own server. Shared hosting customers typically cannot modify global proxy timeouts and should contact their provider instead.

  1. Access your server via SSH or your hosting control panel's File Manager.
  2. Locate your Apache virtual host configuration or nginx.conf file.
  3. For Apache, adjust the ProxyPass timeout parameter in your virtual host configuration:
ProxyPass / http://backend-server/ timeout=300
  1. For Nginx, add or adjust these values within the http, server, or location block:
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
  1. Save the file and restart your web server (for example, sudo systemctl restart apache2 or sudo systemctl restart nginx).
  2. Test your website again.
Increasing timeouts can mask underlying performance issues. If scripts consistently require long execution times, investigate database queries or inefficient code rather than simply extending limits.

5. Troubleshoot Cloudflare or CDN Proxy Timeouts

If your website uses Cloudflare or another CDN, the 504 error may originate from the proxy service rather than your hosting server. Cloudflare typically returns a 504 when its edge servers cannot reach your origin server within the timeout period.

  1. Log in to your Cloudflare dashboard.
  2. Select your domain and navigate to Network > Logs or review the Overview page for error analytics.
  3. Check whether the 504 page displays cloudflare branding, which indicates the timeout occurred at the CDN edge.
  4. Temporarily pause Cloudflare by switching the orange cloud icon to grey for your A record in the DNS section to bypass the proxy.
  5. Test your website directly. If the error disappears, the issue is likely between Cloudflare and your origin server.
  6. Contact your hosting provider to confirm that your origin server is not blocking Cloudflare IP addresses or rate-limiting requests.

Troubleshooting

504 Errors on Specific Pages or Actions

If the 504 error occurs only on specific pages or actions—such as contact form submissions, checkout pages, or product imports—the issue is likely related to a particular script or database query rather than general server overload.

Geographical Latency for Domestic Traffic

If your server is hosted overseas, Australian visitors may experience higher latency, increasing the likelihood of timeouts during resource-intensive operations.

Slow Load Times and Unreliability

Intermittent 504 errors often signal that your hosting environment has been outgrown.

When to Escalate

If you have completed the steps above and the 504 error continues, the issue may be with your hosting provider's infrastructure or a misconfigured upstream server that is outside your control.

Remember — If you host with us, you don't need to do this yourself — just Open a Ticket and our team will get it sorted.

Still Having Issues?

Need more help? If the issue persists after trying these steps, please open a support ticket and our team will assist you.

💻 Open a Ticket