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.
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
- Refresh your browser page to see if the error clears.
- Clear your browser cache and cookies.
- Try accessing your website from a different network or mobile device.
- 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.
- Log in to your hosting control panel (such as cPanel, Plesk, or your provider's custom dashboard).
- Navigate to the Resource Usage, CPU and Concurrent Connection Usage, or Statistics section.
- Review the graphs for CPU, memory, and entry processes.
- If you see sustained spikes at or near 100%, your plan may be underpowered for your current traffic.
- Consider upgrading your hosting plan or optimising your website to reduce resource consumption.
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.
- Log in to your hosting control panel.
- Navigate to Metrics > Errors (cPanel) or the equivalent Logs section in your dashboard.
- Look for entries containing
504,gateway timeout,upstream timed out, orPHP-FPM. - If you use WordPress, enable debugging by adding the following lines to your
wp-config.phpfile:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
- Reproduce the error on your website, then check the
wp-content/debug.logfile via FTP or File Manager for fatal errors or slow query warnings.
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.
- Log in to your website's administration area (for example, WordPress wp-admin).
- Go to Plugins > Installed Plugins.
- Deactivate any recently installed or updated plugins, especially those that connect to external APIs, payment gateways, or shipping calculators.
- Refresh your website to check if the error disappears.
- Reactivate plugins one at a time to identify the problematic integration.
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.
- Access your server via SSH or your hosting control panel's File Manager.
- Locate your Apache virtual host configuration or
nginx.conffile. - For Apache, adjust the
ProxyPasstimeout parameter in your virtual host configuration:
ProxyPass / http://backend-server/ timeout=300
- For Nginx, add or adjust these values within the
http,server, orlocationblock:
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
- Save the file and restart your web server (for example,
sudo systemctl restart apache2orsudo systemctl restart nginx). - Test your website again.
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.
- Log in to your Cloudflare dashboard.
- Select your domain and navigate to Network > Logs or review the Overview page for error analytics.
- Check whether the 504 page displays
cloudflarebranding, which indicates the timeout occurred at the CDN edge. - Temporarily pause Cloudflare by switching the orange cloud icon to grey for your
Arecord in the DNS section to bypass the proxy. - Test your website directly. If the error disappears, the issue is likely between Cloudflare and your origin server.
- 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.
- Identify the exact URL or action that triggers the error.
- Check your application error logs for entries corresponding to that page or action.
- For WordPress sites, review
wp-content/debug.logafter reproducing the error. - Disable any plugins associated with that functionality (for example, a form plugin or payment gateway extension) and test again.
- If the issue involves a database-heavy page, optimise your database tables or reduce the number of records loaded in a single query.
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.
- Use a website speed testing tool to measure load times from Australian locations.
- Consider enabling a Content Delivery Network (CDN) to cache static assets closer to your visitors.
- If latency remains high, migrating to an Australian-based server may improve responsiveness.
Slow Load Times and Unreliability
Intermittent 504 errors often signal that your hosting environment has been outgrown.
- Monitor your site during peak business hours to see if errors correlate with traffic spikes.
- Review error logs in your hosting control panel for
504orgateway timeoutentries. - Optimise images, enable caching, and minify CSS and JavaScript to reduce server load.
- If issues persist despite optimisation, upgrade to a plan with higher resource allocations.
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?
💻 Open a Ticket