
WordPress 504 Bad Gateway Error: How to Fix It
The 504 Gateway Timeout is one of the most common HTTP error codes on WordPress sites. It signals that your server did not receive a response in time from another upstream server. The result: your visitors see an error message instead of your content, and your site loses traffic, conversions, and credibility.
In 2025, 504 errors represent approximately 15% of server incidents reported by WordPress users. This guide explains exactly what causes this error, how to diagnose it, resolve it in 11 steps, and prevent it from recurring.
How to fix a WordPress 504 Bad Gateway error (8 etapes)
- 1
Clear browser and site cache — Purge your browser cache and any server or CDN caching layers.
- 2
Check server error logs — Review Nginx or Apache logs to identify the timeout source.
- 3
Increase PHP and server timeouts — Raise max_execution_time and proxy timeout values in config.
- 4
Deactivate plugins one by one — Disable plugins via FTP to isolate a slow or broken one.
- 5
Test your database performance — Run slow query logs to find database bottlenecks causing delays.
- 6
Check external API dependencies — Identify third-party API calls that may be timing out.
- 7
Upgrade hosting resources — Increase PHP workers, RAM, or move to faster hosting if needed.
- 8
Contact your hosting provider — Escalate to support if the issue persists after all local fixes.
Understanding the 504 Gateway Timeout Error on WordPress
What Is a 504 Gateway Timeout Error?
The 504 error is an HTTP response code indicating that a server acting as a gateway or proxy server did not receive a response within the allotted time from an upstream server. In simple terms, an intermediary server is waiting for a response from another server, but the latter takes too long to respond.
On a WordPress site, the typical scenario unfolds as follows:
- A visitor requests a page on your site
- The web server (Nginx or Apache) forwards the request to PHP-FPM to execute WordPress code
- PHP-FPM queries the MySQL database and executes active plugins and themes
- If this processing exceeds the configured timeout, the web server returns a 504 error to the browser
The error can appear in different forms depending on the server and browser:
- "504 Gateway Timeout"
- "504 Gateway Time-out"
- "HTTP Error 504"
- "Gateway Timeout (504)"
- A white screen with no specific message, similar to the WordPress White Screen of Death
The HTTP Request Lifecycle: When and Why Does a 504 Occur?
To understand the 504 error, visualize the complete path of a web request through the HTTP protocol:
Browser -> CDN (Cloudflare) -> Web Server (Nginx) -> PHP-FPM -> MySQL
<- Response
Each link in this chain has a timeout value. When Nginx waits for a response from PHP-FPM for more than 60 seconds (default value), it gives up and returns a 504 error to the visitor. This behavior protects the server against requests that would consume resources indefinitely.
The timeout can occur at several levels:
- Between the CDN and the web server: the CDN does not get a response from the origin server
- Between the web server and PHP-FPM: a PHP script runs for too long
- Between PHP-FPM and MySQL: a database query takes too much time
- Between the server and an external API: a call to a third-party service does not respond
5xx Errors: Distinguishing the 504 from the 502 Bad Gateway and 503 Service Unavailable
HTTP errors in the 5xx family all originate from the server, but each reflects a different problem:
- 502 Bad Gateway Error: the proxy server received an invalid response from the upstream server. The server responded, but its response is corrupted or incomprehensible. Typical cause: PHP-FPM crash or PHP process terminating abruptly
- 503 Service Unavailable Error: the server is temporarily unavailable, often intentionally (WordPress maintenance mode active, PHP process limit reached, server restarting)
- 504 Gateway Timeout Error: the proxy server received no response within the allotted time. The upstream server is probably still processing the request, but too slowly
| Error | Meaning | Server responds? | Primary cause |
|---|---|---|---|
| 502 | Bad response | Yes, but invalid response | PHP crash, server error |
| 503 | Service unavailable | No, temporarily | Maintenance, overload |
| 504 | Gateway timeout | No, time exceeded | Slowness, PHP/SQL timeout |
This comparison table helps you quickly identify the error type and guide your diagnosis. To learn more about WordPress errors, see our WordPress bugs resolution guide.
Common Causes of the 504 Error on WordPress
Server Overload or Insufficient Hosting Resources
An undersized server for the traffic it receives is the most frequent cause of 504 Gateway Timeout errors:
- Shared hosting: resources (CPU, RAM) are shared with other sites. When your neighbors consume too many resources, your site suffers directly
- Traffic spikes: a viral article, marketing campaign, or seasonal event can overwhelm the server within minutes
- DDoS attacks: a massive flood of malicious requests saturates server resources, making your site unreachable
- WordPress cron processes: scheduled tasks (backups, email sending, WooCommerce synchronization) running simultaneously consume critical resources
If your web host does not provide sufficient resources, even a well-optimized site will trigger 504 errors during peak periods.
Plugin and Theme Conflicts
Some WordPress plugins and WordPress themes consume disproportionate server resources:
- Backup plugins (UpdraftPlus, BackupBuddy) compressing large files during page loads
- Analytics plugins executing heavy queries on every visit
- Page builders (Elementor, Divi, WPBakery) generating complex SQL queries and multiplying PHP calls
- WooCommerce plugins calculating prices, stock, and promotions in real time on every product page
- Misconfigured cache plugins that paradoxically overload the server instead of relieving it
A conflict between two plugins or between a plugin and your theme can also cause infinite loops or API calls that never terminate, exceeding PHP's max_execution_time.
WordPress Database Problems
The WordPress database (MySQL or MariaDB) is often the bottleneck:
- Large tables: the
wp_optionstable can reach hundreds of thousands of rows due to data accumulated by plugins - Missing indexes: queries without indexes scan the entire table, considerably slowing down processing
- Excessive autoloaded data: too much data automatically loaded from
wp_optionson every request - Table locks: concurrent queries block each other, creating congestion
- Revisions and transients: old post revisions and expired transients clutter the database unnecessarily
Firewall (WAF), CDN, or Proxy Configuration
A misconfigured CDN (Content Delivery Network) or WAF (Web Application Firewall) can trigger 504 errors:
- The CDN cannot communicate with the origin server within the allotted time
- Timeout settings on the CDN or proxy server are configured too low
- The SSL certificate between the CDN and the origin server is invalid or expired
- The firewall blocks legitimate requests between servers, causing timeouts
- Overly aggressive security rules in plugins like Wordfence or Sucuri intercept normal traffic
DNS Resolution Problems
DNS (Domain Name System) issues prevent correct domain name resolution:
- DNS propagation in progress: after a server or registrar change, propagation can take up to 48 hours
- Registrar DNS servers down: if the DNS servers managing your domain are unavailable, the site becomes unreachable
- Incorrect DNS records: misconfigured A, CNAME, or AAAA records direct requests to the wrong IP address
PHP Execution Time Too Short
The max_execution_time PHP directive defines the maximum duration for script execution. Its default value (30 seconds) is often insufficient for complex WordPress sites:
- Heavy operations like WooCommerce product imports, report generation, or image processing easily exceed this limit
- Slow external API calls (payment gateways, shipping services, marketing tools) block PHP-FPM execution
- Poorly controlled recursive functions in plugin or theme code consume available execution time
Impact of the 504 Bad Gateway Error on Your WordPress Site and SEO
A 504 bad gateway error on WordPress is not just a technical inconvenience. Its consequences directly affect your business, visibility, and user trust.
Degraded User Experience and Lost Conversions
An inaccessible WordPress site sends an immediate negative signal to visitors:
- Increased bounce rate: users leave your site and turn to a competitor
- Lost sales: on a WordPress e-commerce site (WooCommerce), every minute of downtime represents a direct revenue loss
- Lost contact forms: prospects trying to reach you abandon when facing the error
- Damaged credibility: visitors who encounter a 504 error multiple times associate your brand with unreliability
Negative Impact on Search Engine Optimization (SEO)
Search engines like Google are sensitive to recurring server errors on WordPress sites:
- Page deindexation: if Googlebot encounters a 504 bad gateway error during crawling, it may temporarily remove the page from the index
- Reduced crawl budget: Google allocates a limited number of requests per site. Repeated 504 errors reduce this budget, slowing down the indexation of your content
- Position loss: a WordPress site that is regularly unavailable sees its rankings drop in favor of more stable competitors
- Core Web Vitals impact: timeouts degrade the performance optimization metrics measured by Google
Reputation and Security Risks
In some cases, the 504 Gateway Timeout error on WordPress can mask a more serious problem:
- Ongoing DDoS attack: the 504 error may be the visible symptom of deliberate server saturation
- Malicious code: a compromised WordPress plugin or theme can generate request loops that overload the server
- Brute force attempts: bots trying to force access to
/wp-adminsaturate server resources
If the 504 error repeats without an obvious technical cause, consider a comprehensive security audit. See our WordPress security guide for strengthening your protection.
Advanced Diagnosis: Quickly Identifying the Source of the 504 Error
Before testing solutions one by one, a structured diagnosis saves you valuable time and helps identify the exact cause of the 504 bad gateway error on your WordPress site.
First Steps: Reload and Clear Caches
Always start with the simplest checks:
- Press Ctrl + F5 (Windows) or Cmd + Shift + R (Mac) for a hard page refresh
- Clear your browser's complete cache
- Test with another browser or in incognito mode
- Test from another device or network (mobile on 4G/5G for example)
- Check whether the error affects the entire site or only specific pages
If the error is intermittent and disappears after a refresh, it is likely related to a temporary server overload.
In-Depth Examination of Error Logs (Server and PHP)
Error logs contain precise information about the timeout source:
# Nginx error logs
tail -f /var/log/nginx/error.log
# Apache error logs
tail -f /var/log/apache2/error.log
# PHP-FPM logs
tail -f /var/log/php-fpm/error.log
# WordPress debug log
tail -f /path/to/wp-content/debug.logTo enable WordPress debug mode and capture PHP errors:
// In wp-config.php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);Look for messages containing "upstream timed out" (Nginx) or "Timeout waiting for idle object" (Apache) in the logs, which confirm a 504 error linked to PHP-FPM.
Using Browser Developer Tools
The Network tab in your browser's developer tools (F12) reveals valuable information:
- The exact HTTP status code returned by the server (504, 502, 503)
- The response time of each request, helping identify the slowest calls
- Response headers indicating which server generated the error (Nginx, Cloudflare, Apache)
- Blocking requests: scripts or API calls delaying the complete page load
Checking Server Status and WordPress Services
If you have SSH access or a control panel at your web host, check service status:
# Check if Nginx is running
systemctl status nginx
# Check if PHP-FPM is running
systemctl status php8.2-fpm
# Check if MySQL is running
systemctl status mysql
# Check server load
top -bn1 | head -5
# Check memory usage
free -hA stopped or overloaded PHP-FPM or MySQL service is often the direct cause of the 504 error on WordPress.
Online Diagnostic Tools
Several free tools allow you to check your WordPress site status from the outside:
- Down For Everyone Or Just Me: checks if your site is globally accessible
- DNS Checker: verifies DNS propagation for your domain
- GTmetrix or PageSpeed Insights: analyzes performance and identifies bottlenecks
- Query Monitor (WordPress plugin): displays slow SQL queries, costly hooks, and external HTTP calls directly in your dashboard
Complete Guide to Fixing the 504 Bad Gateway Error on WordPress
WordPress-Specific Solutions
Disable Plugins One by One
WordPress plugins are the most frequent cause of WordPress-related 504 errors. If the dashboard is accessible:
- Go to Plugins > Installed Plugins
- Deactivate all plugins
- Test your site
- Reactivate plugins one by one, testing after each reactivation
If the dashboard is inaccessible, use FTP or your host's file manager:
# Rename the plugins folder to deactivate everything at once
cd /path/to/wp-content/
mv plugins plugins_disabled
# If the site works, rename to reactivate
mv plugins_disabled plugins
# Then deactivate plugins individually
cd plugins/
mv suspect-plugin suspect-plugin_disabledTemporarily Switch WordPress Theme
If disabling plugins does not resolve the issue, test with a default WordPress theme:
# Via FTP, rename your active theme
cd /path/to/wp-content/themes/
mv my-theme my-theme_disabledWordPress will automatically switch to Twenty Twenty-Five or the installed default theme. If the 504 error disappears, your theme is the culprit.
Optimize and Repair the WordPress Database
An overloaded WordPress database is a frequent source of timeouts. Here are the essential operations:
-- Check table sizes
SELECT table_name,
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS 'Size (MB)'
FROM information_schema.TABLES
WHERE table_schema = 'wordpress_db_name'
ORDER BY (data_length + index_length) DESC;
-- Delete excessive revisions
DELETE FROM wp_posts WHERE post_type = 'revision';
-- Delete expired transients
DELETE FROM wp_options WHERE option_name LIKE '%_transient_timeout_%'
AND option_value < UNIX_TIMESTAMP();
-- Check autoloaded data
SELECT option_name, LENGTH(option_value) AS size
FROM wp_options WHERE autoload = 'yes'
ORDER BY size DESC LIMIT 20;You can also use WP-CLI (wp db optimize) or a plugin like WP-Optimize to automate cleanup.
Increase PHP Limits
Default PHP limits are often insufficient for complex WordPress sites. Progressively increase max_execution_time and allocated memory:
Via wp-config.php:
define('WP_MEMORY_LIMIT', '256M');
define('WP_MAX_MEMORY_LIMIT', '512M');Via php.ini:
max_execution_time = 300
memory_limit = 256M
max_input_time = 300
max_input_vars = 5000Via .htaccess (Apache servers):
php_value max_execution_time 300
php_value memory_limit 256MCheck and Fix the .htaccess File
The .htaccess file controls URL rewrites and security rules on Apache servers. A corrupted file can trigger 504 errors:
- Rename
.htaccessto.htaccess.bkvia FTP - Create a new
.htaccessfile with default WordPress rules:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress- Test your site. If the error disappears, a plugin or custom rule in the old
.htaccesswas the cause
Server and Hosting Solutions
Increase Web Server Timeouts
The web server timeout must be greater than the PHP execution time to prevent 504 errors.
For Nginx, add in the http or server block:
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
fastcgi_read_timeout 300;For Apache, add in the virtual host configuration:
Timeout 300
ProxyTimeout 300Contact Your Web Host
If no WordPress-level solution works, the problem is likely server-side. Contact your web host providing:
- The exact time and frequency of 504 errors
- The affected pages (all or specific)
- Actions already attempted
- Relevant log excerpts
The host can check MySQL server status, resource limits, PHP-FPM configuration, and overall server load.
Check Server Load and Resources
If you have SSH access:
# CPU and memory load
top -bn1 | head -10
# Available disk space
df -h
# Number of active PHP-FPM processes
ps aux | grep php-fpm | wc -lInsufficient disk space or an excessive number of active PHP-FPM processes frequently trigger 504 bad gateway errors on WordPress.
Network and Security Solutions
Temporarily Disable the CDN, Firewall, or Proxy
If you use a CDN (Cloudflare, Sucuri, KeyCDN) or a WAF (Web Application Firewall):
- Purge the CDN cache completely from the CDN dashboard
- Test without the CDN by temporarily switching DNS to "DNS only" mode (on Cloudflare, switch from the orange cloud to the gray cloud)
- Check timeout settings on the CDN and increase them if necessary
- Verify the SSL certificate between the CDN and your origin server
Change DNS Servers
DNS problems can cause 504 errors. Flush the local DNS cache:
# macOS
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
# Windows
ipconfig /flushdns
# Linux
sudo systemd-resolve --flush-cachesSwitch your DNS servers to reliable public servers like Google DNS (8.8.8.8 / 8.8.4.4) or Cloudflare DNS (1.1.1.1 / 1.0.0.1). Verify propagation via DNS Checker.
Check VPN Settings
If you use a VPN, temporarily disable it and retest access to your site. The VPN server may not be able to get a response from your host, triggering a 504 timeout.
Special Case: Could the 504 Error Be Hiding an Attack?
In rare cases, a recurring 504 Gateway Timeout error on WordPress can be a symptom of malicious activity:
- DDoS attack: a massive flood of requests deliberately saturates your server
- Compromised plugin or theme: malicious code generates request loops or calls to third-party servers
- Brute force on
/wp-login.php: bots attempt thousands of password combinations, consuming server resources
If you suspect an attack, restrict access to /wp-login.php and /xmlrpc.php, enable DDoS protection on your CDN, and consult our WordPress security guide.
Prevention: How to Avoid Future 504 Errors on Your WordPress Site
Preventing 504 bad gateway errors is more effective and less costly than fixing them in an emergency. Here are the best practices to implement on your WordPress site.
Active Server and Performance Monitoring
Set up continuous monitoring to detect issues before they become critical:
- UptimeRobot or Pingdom: email or SMS alerts as soon as a 504 error is detected
- New Relic or Query Monitor: identification of slow SQL queries and costly PHP hooks
- Google Search Console: monitoring of crawl errors reported by Googlebot
- Schedule monthly log reviews to spot slowdown trends on your server
Optimizing Your WordPress Site Resources
Performance optimization of your site reduces the risk of timeouts:
- Compress and optimize images: use WebP or AVIF format and enable WordPress native lazy loading
- Minimize HTTP requests: combine CSS and JavaScript files, disable unnecessary scripts on pages where they are not needed
- Limit active plugins: each plugin adds code executed on every page load. Audit regularly and remove unnecessary WordPress plugins
- Optimize the database at least once a month: clean up revisions, expired transients, and orphaned tables
Keep WordPress, Plugins, and Themes Updated
WordPress core, plugin, and theme updates include performance, security, and compatibility fixes. Follow our WordPress maintenance guide for a structured update schedule.
Important: always test updates on a staging environment before applying them to production. An incompatible update can itself trigger a 504 error.
Choose a Robust and Scalable Web Host
Your web host is the foundation of your site's availability:
- Managed WordPress hosting (Kinsta, WP Engine, Cloudways): dedicated resources, specialized WordPress support, built-in server optimizations
- Avoid shared hosting for high-traffic sites or WooCommerce stores: shared resources are the primary cause of 504 errors during traffic spikes
- Plan for scalability: choose a host capable of automatically increasing resources during traffic peaks
Implement an Effective Caching Strategy
A well-configured caching system drastically reduces server load:
- Cache plugin: WP Rocket, LiteSpeed Cache, or W3 Total Cache serve static pages instead of hitting PHP and MySQL on every request
- CDN: Cloudflare or another CDN distributes static content from servers close to your visitors, reducing the load on your origin server
- Object cache (Redis or Memcached): stores database query results in memory for instant access
For professional maintenance and optimization of your site, discover our WordPress maintenance service.
Frequently Asked Questions (FAQ) About the 504 Gateway Timeout Error
How can I monitor my WordPress site to prevent 504 errors?
Use a monitoring service like UptimeRobot (free for up to 50 monitors) or Pingdom to receive real-time alerts whenever your site returns a 504 error. Supplement with Google Search Console to track crawl errors detected by Googlebot. Internally, install the Query Monitor plugin to identify slow SQL queries and problematic PHP hooks directly in your WordPress dashboard.
Can the 504 error be caused by a security issue or DDoS attack?
Yes. A DDoS attack (Distributed Denial of Service) saturates your server with a massive volume of simultaneous requests, causing 504 timeouts. Similarly, brute force attempts on /wp-login.php or malicious scripts injected into a compromised plugin can consume all server resources. If 504 errors appear suddenly without recent modifications to your site, check access logs for suspicious patterns and enable DDoS protection on your CDN.
What is the fundamental technical difference between a 504 and a 502 error?
The 502 Bad Gateway error indicates that the proxy server received an invalid response from the upstream server: the server responded, but its response is corrupted or incomprehensible (often due to a PHP-FPM crash). The 504 Gateway Timeout error indicates that the proxy server received no response within the configured timeout: the upstream server is probably still processing the request, but too slowly. In summary, 502 is an invalid response problem, 504 is a timeout problem.
How do I optimize my WordPress database to avoid timeouts?
Start by deleting excessive post revisions (DELETE FROM wp_posts WHERE post_type = 'revision'), then clean up expired transients and unnecessary autoloaded data in the wp_options table. Verify that your tables have adequate indexes and run regular optimization via WP-CLI (wp db optimize) or a plugin like WP-Optimize. For high-traffic sites, implement an object cache (Redis or Memcached) to reduce the number of direct SQL queries. Schedule these operations at least once a month, or weekly for e-commerce sites.
The 504 Bad Gateway error on WordPress is generally a symptom of a performance or server configuration issue. In the majority of cases, it can be resolved by optimizing plugins, the database, or PHP settings.
If you want to permanently eliminate server errors and guarantee your site's availability, discover our WordPress maintenance service for professional support.
Related articles:
