DroidCrunch
  • About
  • Blog
  • Categories
    • Automation
    • Tech
    • SEO
    • WordPress
    • Software
    • Hosting
    • Proxy
  • AI
    • AI Writing
    • AI Image
    • AI Tool
    • AI Video
  • Deals
  • Contact
Subscribe
No Result
View All Result
DroidCrunch
  • About
  • Blog
  • Categories
    • Automation
    • Tech
    • SEO
    • WordPress
    • Software
    • Hosting
    • Proxy
  • AI
    • AI Writing
    • AI Image
    • AI Tool
    • AI Video
  • Deals
  • Contact
Subscribe
DroidCrunch

502 Bad Gateway: What It Means and How to Fix It 2026

Lokesh Kapoor by Lokesh Kapoor
November 4, 2026
3
0

Your site was fine an hour ago. Now every page says 502 Bad Gateway.

Short answer: the server in front of your site, usually Nginx or Cloudflare, got a broken reply from the app behind it. On WordPress that app is PHP-FPM. Restart it, or fix what crashed it, and the error clears.

We broke a test server six ways to see what each 502 error leaves behind.

The log line tells you the fix. Most guides never show it to you.

What does 502 Bad Gateway mean?

A 502 Bad Gateway means a gateway or proxy got an invalid response from the server behind it. That’s how RFC 9110, the HTTP standard, defines it.

So the error has two parties, and neither of them is your browser.

  • The gateway takes your request first: Nginx, Apache acting as a proxy, a load balancer or a CDN.
  • The upstream builds the page: PHP-FPM for WordPress, a Node or Python app, or your origin server when a CDN sits in front.
  • The 502 is the gateway saying the upstream refused the connection, hung up halfway or sent something that wasn’t valid HTTP.
Where a 502 Bad Gateway happens: the request reaches the gateway fine, but the app server behind it sends a bad reply or none
Your request reaches the gateway without trouble. The 502 is the gateway reporting that the server behind it failed to give a usable answer.

That’s why a 502 is almost never fixed on the visitor’s side. The page you see comes from a working server that is reporting a broken one behind it. If you run a hosted site, our guide to how web hosting works shows where each of these layers lives.

Seeing a 502 on someone else’s site? Try these three things

If it isn’t your site, you have very little to fix. Do these in order and stop when the page loads.

  • Wait 60 seconds and reload. Many 502s last only while a server restarts or a deploy finishes.
  • Open it on mobile data or another network. If it loads there, a proxy, VPN or office firewall between you and the site is the gateway that’s failing.
  • Turn off your VPN or proxy. A proxy is a gateway too, and a dead exit server returns its own 502. Our common proxy errors guide covers that case.

Clearing your cache or cookies rarely helps with a 502, with one exception we’ll get to: oversized cookies.

We broke an Nginx server six ways on purpose

In November 2026 we set up Nginx 1.26 as a reverse proxy on our Linux test box, with small test apps behind it. Then we broke the apps one at a time and read what Nginx wrote to its error log.

It’s a lab, not a production WordPress site. But the log lines are the same ones you’ll find on a real server, and they’re the fastest route to the fix.

What we brokeWhat the visitor gotWhat Nginx logged
App not running502 in under 1 msconnect() failed (111: Connection refused)
App hung up mid-request502upstream prematurely closed connection
App sent a 6,000-character cookie502upstream sent too big header
PHP socket path wrong502connect() to unix:/run/php/php8.3-fpm.sock failed (2: No such file or directory)
App took 10 seconds to answer504 after exactly 3 supstream timed out (110: Connection timed out)
One of two app servers down200 on 10 of 10 requestsupstream server temporarily disabled

Two patterns jump out. A 502 usually arrives instantly, because the gateway knew right away the reply was bad. A slow app gives you a 504 instead, timed to the gateway’s limit.

And look at the last row. With a second app server in the pool, Nginx quietly retried and every visitor got the page.

Here’s what Nginx sends back. The whole error page is 157 bytes:

curl -sI http://127.0.0.1:8080/down/ Plain text
HTTP/1.1 502 Bad Gateway
Server: nginx/1.26.3
Content-Type: text/html
Content-Length: 157

How to fix a 502 Bad Gateway on your own site

Start with the error log, not with guesses. On most Nginx servers it lives at /var/log/nginx/error.log, and the newest lines sit at the bottom.

terminal Bash
sudo tail -n 20 /var/log/nginx/error.log
# then check the app behind it, for WordPress usually:
systemctl status php8.3-fpm

Match the log line to our table. Then apply its fix:

Fix a 502 from the log line up

Each step matches one error Nginx writes when the upstream fails.

  1. 1
    Step 1 of 5

    Connection refused: start the app

    PHP-FPM or your app isn’t running. Restart it with systemctl restart php8.3-fpm (use your version), then check its own log for why it stopped. Out-of-memory kills are the usual culprit.

  2. 2
    Step 2 of 5

    No such file or directory: fix the socket path

    Nginx is pointing at a PHP socket that doesn’t exist, often right after a PHP version upgrade. Make fastcgi_pass match the listen line in your PHP-FPM pool config, then reload Nginx.

  3. 3
    Step 3 of 5

    Prematurely closed: find what crashed the worker

    The PHP worker died mid-request. Check the PHP error log and the WordPress debug log for a fatal error, then disable the plugin named in it.

  4. 4
    Step 4 of 5

    Too big header: raise the buffer

    The app sent headers bigger than Nginx’s 4 KB default buffer. Set proxy_buffer_size 16k and proxy_buffers 8 16k (fastcgi_buffer_size for PHP), reload, and test again.

  5. 5
    Step 5 of 5

    Behind Cloudflare: check whose error page it is

    A Cloudflare-branded 502 page means your origin server sent the error, so fix the server. A plain, unbranded page means it came from Cloudflare itself.

That buffer fix is the one we proved on the box. The same 6,000-character cookie that broke the page loaded with a 200 OK once we raised proxy_buffer_size to 16k.

Real-world tip: if a 502 appears only after you log in, or only in wp-admin, suspect the header size first. Logged-in sessions carry bigger cookies, and a page builder or security plugin can push them past 4 KB.

Why WordPress sites throw 502s more than most

A WordPress page isn’t a file Nginx can hand over. Every uncached request goes to PHP-FPM, a pool of PHP workers, and that’s the link that breaks.

Three things stress it. A plugin with a fatal error kills its worker mid-page. A traffic spike or a heavy WooCommerce job uses up every worker. And a cheap plan’s memory limit lets the server kill PHP outright when it runs short.

Caching cuts the load hard, because a cached page never reaches PHP at all. That’s one reason a caching plugin like WP Rocket pays off on busy shared plans.

Security plugins and firewalls can also block the connection between the CDN and your server, which looks like a 502 to everyone outside. Our list of WordPress security plugins covers which ones add their own firewall layer.

502, 503 or 504: which one are you looking at?

All three come from a gateway or a struggling server, but each one points to a different problem.

502 vs 503 vs 504: broken reply, server says busy, reply came too late
Three gateway-side errors, three different problems. The number tells you where to look first.
CodeWhat happenedWhere to look first
502 Bad GatewayThe upstream refused, crashed or sent a broken replyError log, then the app or PHP-FPM status
503 Service UnavailableThe server says it can’t take requests right nowMaintenance mode, rate limits, overloaded workers
504 Gateway TimeoutThe upstream was too slow to answerSlow queries, long imports, timeout settings

Our lab showed the difference in seconds. The broken apps failed with a 502 in under 2 milliseconds, while the slow one hit our 3-second limit and came back as a 504.

When the 502s keep coming back, look at your hosting

One 502 is a bug. A 502 every week is a capacity problem.

If your log keeps showing refused connections or killed workers at busy times, your plan doesn’t have enough PHP workers or memory for your traffic. You can tune the pool on a VPS, but on shared hosting you’re stuck with the host’s limits.

Ask your host how many PHP workers your plan allows before you blame WordPress. Our checklist for choosing a web hosting service puts that question near the top.

That’s the point where an upgrade beats another week of restarts. A managed host like Pressable or a bigger Hostinger plan gives you more workers and someone who reads the logs for you. Our managed vs shared WordPress hosting comparison runs the numbers on when that’s worth it.

Prefer to stay in control? Our roundup of VPS hosting services covers plans where you set the worker count yourself.

Disclosure: some links above are affiliate links. We earn a commission if you buy through them, at no extra cost to you.

Frequently Asked Questions

Does a 502 Bad Gateway hurt my SEO?

A short one doesn’t. Google treats 5xx errors as temporary and slows its crawling while they last. If pages keep returning server errors for days, Google starts dropping them from its index, so fix repeat 502s quickly.

Can a WordPress plugin cause a 502 error?

Yes. A plugin with a fatal PHP error can crash the worker building the page. Nginx then reports a 502. Rename the plugin’s folder over SFTP to switch it off and test again.

Why do I get a 502 only when saving a post or uploading?

Saving and uploading are the heaviest requests WordPress makes. A large upload or a slow plugin hook can crash or exhaust a PHP worker. Check the PHP error log at the exact time you saved.

Is a 502 Bad Gateway caused by my internet?

Rarely. The error is sent by a server that’s working. The exception is a proxy, VPN or company firewall you route through, because that’s a gateway too. If the site loads on mobile data, the problem is on your network.

How long does a 502 Bad Gateway usually last?

A 502 caused by a restart or a deploy usually clears within a minute or two. One caused by a crashed service, a wrong socket path or full workers lasts until someone fixes the server, so don’t wait it out.

Why does my site work with Cloudflare paused but show 502 with it on?

Cloudflare connects to your server differently than your browser does. Your firewall may block Cloudflare’s IP ranges, or the server may send broken compressed responses. Cloudflare’s docs name broken gzip as one cause of unbranded 502 pages.

Should I contact my host about a 502?

Yes, if you’re on shared or managed hosting and can’t see the server logs. Send the exact time, the URL and whether it happens on every page. That’s enough for support to find the matching error log line.

The bottom line

A 502 Bad Gateway means the gateway worked and the app behind it didn’t. Visitors can only reload, switch networks or drop their VPN.

Site owners should open the Nginx error log first. Then match the line to its fix: start PHP-FPM, correct the socket, find the crashing plugin or raise the header buffer. If the 502 error returns every busy week, your plan has run out of room, and that’s a hosting decision.

Next step: run tail -n 20 on your error log the next time it happens, before you restart anything. The restart clears the evidence.

Share4Tweet2Share1Share
Previous Post

What Is a VPN Tunnel? How It Works and What It Can’t Hide 2026

Next Post

504 Gateway Timeout: Causes and Fixes That Actually Work 2026

Lokesh Kapoor

Lokesh Kapoor

I am Lokesh Kapoor who loves to write blogs, create videos and watch sci-fi movies on Netflix and Jio Cinema. DroidCrunch is my first love and a crucial part of my life.

Related Posts

Bluehost coupons title card: a checkout card with 60% off applied and Starter at $3.99 a month, no code needed

Bluehost Coupons 2026: Up to 60% Off and Current Offers

November 8, 2026
300
wpDataTables review title card with a data table and bar chart illustration

wpDataTables Review 2026: Which Plan Do You Actually Need?

10 Web Designing Stats to create the perfect website

Unveiling 10 Web Designing Stats to create the perfect website

November 6, 2026
345
Error establishing a database connection on a laptop next to a MySQL database server with a broken link

“Error Establishing a Database Connection”: How to Fix It 2026

November 5, 2026
299
Load More

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I agree to the Terms & Conditions and Privacy Policy.

Youtube Instagram Telegram Discord Facebook Whatsapp Twitter LinkedIn

About

DroidCrunch Logo Dark

DroidCrunch is your trusted blog & YouTube channel dedicated to SAAS lovers, WordPress enthusiasts, and Technology Freaks.

Quick Links

  • About Us
  • Editorial Policy
  • Contact Us
  • Help & Support
  • RSS Feed

© 2026 DroidCrunch - Best Place for Tech NomadPrivacy PolicyTerms & ConditionsCookie PolicyGDPR RightsAffiliate Disclosure

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
Subscribe
  • About
  • Blog
  • Categories
    • Automation
    • Tech
    • SEO
    • WordPress
    • Software
    • Hosting
    • Proxy
  • AI
    • AI Writing
    • AI Image
    • AI Tool
    • AI Video
  • Deals
  • Contact

© 2026 DroidCrunch - Best Place for Tech NomadPrivacy PolicyTerms & ConditionsCookie PolicyGDPR RightsAffiliate Disclosure

DroidCrunch Giveaway

Amazon Gift Card worth $15

Participate now and get a chance to become a lucky winner to receive the reward.​

Join Giveaway