A 502 Bad Gateway in WordPress means the server in front of your site asked your server for a page and got nothing usable back. Two very different failures produce that message, and the time you spent waiting tells you which one you have. An instant 502 and a 502 after thirty seconds of spinning share a number and almost nothing else.
Answer two questions before you change a single setting. They take a minute and they rule out most of the advice you will find elsewhere.
How long did you wait before the error appeared?
This is the most useful signal available to you, and almost nobody mentions it.
Instant, under a second. The proxy could not reach your site at all. PHP is not running, the worker pool is full, or a CDN cannot reach your origin server. Nothing on your site executed, which means no plugin, theme or query is responsible. Skip straight to the backend section below.
Slow, roughly thirty to sixty seconds of loading first. Something on your site started running and never finished, and the server killed it at the timeout. Now a plugin, a database query, an import or a cron job is a real suspect.
If you are not sure, load the page again and count. The difference decides which half of this article applies to you.
Is it one page, or the whole site?
The second question, and it narrows things further.
One page only. Look for a slow database query on that page. Common culprits are an archive pulling hundreds of products, a filtered listing with no limit, a heavy shortcode, or a search page returning everything. Install Query Monitor on a working page and it names the slowest queries and which plugin owns them.
Every page, but only sometimes. Worker exhaustion or a resource limit. Check if the errors line up with traffic peaks, a backup job, or scheduled tasks.
Every page, constantly. Your backend is down. Nothing you change in WordPress will fix this, and your host is the next call.
What 502 actually means, and how it differs from 504 and 500
Most guides to 502 bad gateway WordPress errors treat these three as the same thing. They are not, and the difference changes the fix.
| Code | What actually happened |
| 502 Bad Gateway | The proxy never established a valid connection to your server. The process manager is down, the socket is missing, or the queue is full |
| 504 Gateway Timeout | The connection worked, the request was handed over, and the response never arrived in time |
| 500 Internal Server Error | The connection worked and your site’s own code threw an error |
If you are seeing a 500 error rather than a 502, that guide is the right one. Our roundup of common WordPress errors covers the rest, including the white screen of death.
One behaviour worth knowing, because it explains something confusing. When the proxy gives up, PHP does not stop. The worker keeps building a response nobody is waiting for. So reloading a slow 502 repeatedly does not retry the request, it stacks up more work on a server that is already struggling, which is why the error often spreads to pages that were fine a minute earlier.
If the 502 is instant
Nothing on your site ran, so look below WordPress.
Check that PHP is running at all. On most managed hosts this is a support ticket rather than a setting. The phrase that gets a useful answer: “Is PHP-FPM running correctly for my site, and does it need a restart?”
Check your worker allocation. PHP-FPM handles requests using a fixed pool of workers. When every one is busy, new requests have nowhere to go and the proxy returns 502. This is usually a plan limit rather than a fault. Ask your host how many PHP workers your plan allows.
Check your CDN or firewall. If the error page carries Cloudflare, Sucuri or another provider’s branding, the problem sits between them and your origin. Pause the service temporarily. If the site loads, you have found the layer at fault.
Check .htaccess on Apache setups. Rename it to .htaccess_old over FTP and reload. If the site returns, go to Settings, then Permalinks, and click Save to generate a clean one.
Rule out xmlrpc.php early. A documented case describes a bot hitting that file three times per second, repeatedly killing the PHP process manager. Most sites never use XML-RPC, so heavy traffic to it in your server logs is worth blocking. That single change can end a recurring 502 permanently.
If the 502 takes thirty to sixty seconds
Something ran too long. Work through these in order.
Find the slow query. Query Monitor on a working page shows you total query count, the slowest individual queries, and which plugin owns them. A single query taking several seconds on a page that times out is your answer, and you have it in two minutes rather than by disabling things at random.
Check for plugins making external calls. A plugin fetching from an API without its own timeout will sit there until the server kills the request. Social feeds, shipping lookups, currency converters and review widgets are the usual offenders. Our guide to isolating a plugin that is not working covers the process.
Check scheduled tasks. WordPress runs cron during page loads on lower-traffic sites, so a backup or import can fire while a visitor waits. If the 502s cluster at particular times, that is your answer. Our guide to a slow WordPress admin covers moving cron to a real server schedule.
Check for a running import or export. Bulk operations are the most common cause of a one-off 502, and the fix is smaller batches rather than any setting change.
If the real issue is general slowness rather than one blocking request, our guide to fixing a slow WordPress website is the better starting point.
Why raising the timeout is usually the wrong fix
Almost every article on 502 bad gateway WordPress errors tells you to increase max_execution_time. It is the most common advice and it usually treats the symptom.
The timeout is doing its job. It is telling you some requests take longer than your site should ever take. Raising it does not make the page work, it makes the failure slower. The visitor waits ninety seconds instead of thirty for the same error, and that request holds a PHP worker the whole time, which means fewer workers for everyone else.
Raise the timeout only as a temporary measure while you fix the slow thing, then put it back. We are not a hosting company, so there is no version of this where the answer is conveniently “upgrade your plan”.
Is this your fault or your host’s?
A fair question, and the honest answer splits down the middle.
Treat it as yours when the 502 takes thirty seconds or more, affects one specific page, or started right after you installed something or ran an import. Something on the site is doing too much work.
Treat it as your host’s when the 502 is instant, affects every page, clears on its own without you touching anything, or hits other sites on the same account at the same time.
One middle case catches people out. Worker exhaustion looks like a site problem and is often a plan problem. If traffic has grown and the 502s appear at busy times, you may have outgrown the allocation you are paying for.
Key takeaways
A 502 bad gateway WordPress error has two distinct causes, and the wait before it appears tells you which. Instant means the backend was unreachable and nothing on your site ran. Thirty seconds or more means something ran and got killed at the timeout.
Then narrow by scope. One page points at a slow query on that page. Every page intermittently points at worker limits. Every page constantly points at your host.
Resist the standard advice to raise the timeout. It converts a fast failure into a slow one and ties up a worker while it does. Fix what is slow, then leave the timeout where it was.
Frequently asked questions
What causes a 502 bad gateway WordPress error?
Either the server in front of your site could not reach it at all, or it reached it and the response took too long. The first is usually PHP not running, exhausted workers, or a CDN failing to reach your origin. The second is a slow query, a plugin making external calls, or a bulk operation.
Why does 502 only appear on one page?
Because that page does something the others do not, almost always a slow database query. Archive pages pulling hundreds of items, filtered listings without limits and unrestricted search pages are the usual causes. Query Monitor names the query and the plugin responsible.
What is the difference between 502 and 504 errors?
A 502 means the proxy never established a valid connection to your server. A 504 means the connection succeeded but the response did not arrive before the timeout. Most WordPress guides treat them as the same thing, and the distinction matters because one is a connection problem and the other is a speed problem.
Should I increase max_execution_time to fix a 502?
Only temporarily, while you fix what is slow. Raising the timeout makes the failure take longer rather than making it stop, and the request holds a PHP worker for that entire time, which makes the problem worse for other visitors. Find the slow query instead.
Will a 502 error hurt my SEO?
A brief outage will not. Repeated 502s can, because crawlers hitting errors slow their crawl rate and eventually return less often. Fix the cause rather than waiting it out, particularly if the errors recur at predictable times.
Still seeing 502s and not sure why?
If the page fails instantly, your host owns it, and the fastest route is a ticket quoting what you read here. If it fails slowly and you cannot find the query, that is work we do every week. Survyc is an AI-first digital agency that diagnoses and fixes WordPress server errors. Send the URL and tell us how long the page spins first, since that alone narrows it considerably. Our guide to what a WordPress repair costs covers pricing, and our emergency downtime triage guide covers the other ways a site goes dark. Get in touch or email info@survyc.com.