Operations

502 Bad Gateway, 500, 503 and 504 errors: what they mean and how to fix them (2026)

7 min read By Cloud Ninza

A 5xx error means the server, not the visitor, has a problem. Each number points to a different cause — here is how to read them and fix the real problem quickly.

In short 5xx errors mean the server failed, not the visitor. A 500 means the application itself crashed while handling the request (often a PHP error, a bad plugin or a wrong setting). A 502 Bad Gateway means the web server could not get any answer from the app behind it — the app is stopped, crashing or listening on the wrong port. A 503 means the service is temporarily unavailable (maintenance, overload or a suspended account), and a 504 means the app answered too slowly. The error log tells you which line or process failed; fix that and the error disappears.

First, the one thing every 5xx error has in common

Status codes that start with 5 mean the server could not complete a request that was otherwise fine. Clearing the browser cache, trying another browser or reinstalling anything on the visitor's computer will not help. The answer is always on the server side: in the application, its settings, or the server it runs on.

On modern hosting, a request usually passes through two layers: a web server such as nginx, which receives the visitor's connection and handles SSL, and the application behind it — PHP-FPM for WordPress and PHP, or your own Node.js, Python or Java process. Knowing which layer produced the error halves the work, and the number tells you.

500 Internal Server Error: the app crashed

A 500 means the request reached your application, and the application failed while handling it. The web server is fine; your code, plugin or configuration is not. Typical causes:

  • A PHP fatal error, often after updating a WordPress plugin or theme, or switching to a newer PHP version the code does not support.
  • Wrong database details in wp-config.php, .env or settings.py, or a database user without permission.
  • A syntax error in a configuration file, or a missing file after an incomplete upload.
  • File permissions that stop the app reading its own files (folders 755 and files 644 are normal for websites).
  • A Node.js or Python route that throws an unhandled exception for one specific page.

Fix: open the error log — it names the file and line. For WordPress, renaming the newest plugin's folder (or the whole plugins folder) through the File Manager is the fastest test: if the site comes back, re-enable plugins one at a time to find the culprit.

502 Bad Gateway: nothing answered behind the web server

A 502 comes from the web server itself. It tried to pass the request to your app and got no valid answer at all. For WordPress and PHP sites that usually means PHP-FPM is overloaded or restarting. For Node.js, Python and Java apps it almost always means one of these:

  • The app is stopped or keeps crashing on start — a missing environment variable, a database it cannot reach, a module that was never installed.
  • The app listens on the wrong port. On managed platforms the app must read the port from the PORT environment variable instead of a fixed 3000 or 8000.
  • The app listens only on another address, or starts a development server instead of the production one.
  • The app ran out of memory and was restarted, and requests arrived while it was down.
  • The app is still starting — Java and apps that connect to a remote database can take 20–40 seconds after a restart.

Fix: read the app's own log, not just the web server log. The last lines before the crash almost always say exactly what is missing — "Cannot find module", "ECONNREFUSED", "Missing DATABASE_URL", "address already in use".

503 Service Unavailable: deliberately not serving

A 503 means the server is reachable but declines to serve right now. Common reasons: WordPress left in maintenance mode after an interrupted update (a file called .maintenance in the site folder — delete it), WooCommerce's "coming soon" mode, a site or account suspended by the host (often an unpaid renewal), or a server that is overloaded and shedding traffic. Check your hosting dashboard for notices before touching code.

504 Gateway Timeout: the app was too slow

A 504 means the app did answer — just not in time. Something inside a request takes too long: a slow database query, a call to an external API that hangs, a report or export generated while the visitor waits, or an import that should run in the background. Behind Cloudflare, requests are cut at 100 seconds and shown as Cloudflare error 524.

Fix the slow operation rather than raising timeouts: add database indexes, cache results, set timeouts on external API calls, and move long jobs to a background worker or a scheduled cron job that emails the result.

Cloudflare's 52x errors decoded

If your domain uses Cloudflare, errors arrive with Cloudflare's own numbers. They point to the connection between Cloudflare and your server:

  • 520 — the server sent an empty or invalid response (often an app crash mid-response).
  • 521 — the server refused the connection: the web server is down or a firewall blocks Cloudflare.
  • 522 — connection timed out: the server did not answer at all, or the A record points to the wrong IP.
  • 524 — the app took longer than 100 seconds; same fix as a 504.
  • 525 / 526 — SSL problems between Cloudflare and the server; check the SSL mode is Full and the server has a valid certificate.

A five-minute checklist for any 5xx error

Work through it in order; most problems are found by step three:

  • Is it every page or one page? One page points to code; every page points to the app, server or configuration.
  • What changed last? An update, a deploy, a new plugin, a PHP version switch, an expired card — roll that back first.
  • Read the error log: the last 50 lines are usually enough.
  • Is the app running? Check its status and restart it once — if it crashes again, the log tells you why.
  • Is the database reachable, and is the disk or storage full?
  • Still stuck? Contact support with the exact time, URL and error number.

Finding the cause on Cloud Ninza

Everything needed is in the dashboard, without a separate control panel. Logs shows each website's access and error logs. App settings shows a Node.js, Python or Java app's status with Start, Stop and Restart, its environment variables and the live output of the last install and build. The File Manager lets you rename a plugin folder, delete a stuck .maintenance file or fix a configuration file in the browser, and the Terminal runs commands such as wp plugin deactivate --all for WordPress.

Apps deployed from Git get a health check after every deploy: if the new release does not answer, the platform rolls back to the previous release automatically, so a bad commit does not leave visitors on a 502. Every project is also backed up twice a day, so a broken update can be undone from Backups in a few clicks.

Preventing the next one

Most 5xx errors are self-inflicted during changes. Update plugins and dependencies on a staging copy or a quiet hour, keep a fresh backup before every big change, read the PORT and database settings from environment variables, set timeouts on every external call, and watch the error log after each deploy for a few minutes. Uptime monitoring that alerts you on the first failure turns a long outage into a short one.

Key takeaways

The short version, for anyone skimming:

  • 500 = the app crashed; 502 = nothing answered behind the web server; 503 = deliberately unavailable; 504 = too slow.
  • The error log names the cause in nearly every case — read it before changing anything.
  • For Node.js and Python apps, a 502 is usually a crash on start, a missing variable or the wrong port.
  • Cloudflare's 520–526 errors point to the link between Cloudflare and your server.
  • On Cloud Ninza, Logs, App settings, the File Manager and twice-daily backups cover every fix from the dashboard.
Host it with us

Cloud Hosting

Cloud hosting on servers in India from ₹99 a month, billed yearly: WordPress, PHP, Node.js, Next.js, Python and Java, free SSL, Git deployments, SSH, backups and 24x7 engineers. WordPress, PHP, Node.js, Python or Java — your choice of version · Storage and RAM allowance per plan on cloud servers in India · Free SSL certificates, renewed automatically.

Ready when you are

Hosting from ₹99 a month on servers in India

WordPress, PHP, Node.js, Python and Java plans with free SSL and your choice of version. Create your account, pick a plan and pay by UPI, card or netbanking; your hosting is created automatically and you get your login by email, usually within minutes.

Questions

Questions on this topic

What does 502 Bad Gateway mean?

The web server could not get a valid answer from the application behind it — the app is stopped, crashing, still starting or listening on the wrong port.

Is a 502 error my fault or the host's?

Usually the application's: a crash, missing setting or wrong port. If every site on the server is down, it is the host's — check their status page or contact support.

How do I fix a 500 Internal Server Error in WordPress?

Read the error log, then disable the most recently updated plugin by renaming its folder. Also check wp-config.php database details and the PHP version.

What is the difference between 502 and 504?

A 502 means no valid answer came back at all; a 504 means the app was still working when the time limit ran out.

How do I fix a 503 Service Unavailable error?

Delete a leftover .maintenance file after a WordPress update, turn off coming-soon mode, or check your hosting dashboard for a suspension or overload notice.

Why does my Node.js app show 502 after deploying?

It crashed on start or listens on a fixed port. Read the app log, make sure it uses process.env.PORT, and check required environment variables are set.

What is Cloudflare error 522?

Cloudflare could not connect to your server in time — the server is down, a firewall blocks it, or the A record points to the wrong IP.

Can clearing my browser cache fix a 5xx error?

No. 5xx errors are produced by the server. Clearing the cache only helps if you are seeing an old cached error page after the fix.

How long does a 502 error last?

Until the cause is fixed. A brief 502 during a restart lasts seconds; a crash loop lasts until the missing setting or bug is corrected.

Where are error logs on Cloud Ninza?

In your dashboard: Logs shows each website's access and error logs, and App settings shows each app's own output and status.