502 Bad Gateway and 504 Gateway Timeout: What to Do
The server in front of your site got a bad or no answer from the server behind it. Check timeouts, PHP limits and heavy tasks.
These errors come from servers that pass requests to your PHP application. They mean the application crashed, took too long, or was unreachable.
Step 1: Reload, then test another page
If it happens only on one page or action, the cause is likely a slow script there.
Step 2: Check the error log
Your host's error log names slow or crashing scripts. See our PHP error guide.
Step 3: Look at limits
Long imports, backups or reports can exceed the maximum execution time. Raise max_execution_time and the memory limit in your host's PHP settings. See our memory guide.
Step 4: Check plugins
A plugin that calls a slow outside service can cause timeouts. Disable recently added plugins. See our conflict guide.
Step 5: If you use a CDN or proxy
Test with the CDN paused. For Cloudflare, see our Cloudflare errors guide.
Step 6: Server load
If errors come in waves, the server may be overloaded. See our 503 guide and ask your host about restarts and limits.
Related guides
- WordPress White Screen of Death: How to Fix a Blank Page
- WordPress Theme Broke the Site: Switch Back to a Default Theme Without Dashboard Access
- WordPress Posts or Pages Show 404 Not Found but the Homepage Works
- WordPress Pages Show 404 Not Found (Posts Work, Pages Do Not)