Performance

502, 503 and 504 Errors: What They Mean and How to Fix Them

502 Bad Gateway, 503 and 504 errors mean a server behind your site failed to answer properly. Learn what each code means and how to fix it, step by step.

By Zebra Hosting Cloud

A 502 Bad Gateway, 503 Service Unavailable or 504 Gateway Timeout error means your website did not answer properly when a visitor asked for a page. Your files and content are usually fine. In short, a 502 means a server got a broken answer, a 503 means the server is too busy or paused, and a 504 means it waited too long. Many cases clear up within minutes, and the rest can usually be traced with a few checks.

What 502, 503 and 504 mean in plain words

When someone opens your site, the request passes through a chain: Cloudflare (a network in front of your site), then a web server such as nginx or Apache, then PHP, which runs WordPress, and finally the database. Three words help:

  • Gateway (or proxy): a server that takes the request and passes it on to another server.
  • Upstream: the next server in the chain, the one the gateway is waiting for.
  • Timeout: the longest time a server will wait for an answer before it gives up.
CodeWhat it means
502 Bad GatewayThe gateway reached the upstream server but got an invalid answer back.
503 Service UnavailableThe server cannot handle the request right now, usually because it is overloaded or down for maintenance.
504 Gateway TimeoutThe gateway waited for the upstream server, but the answer did not arrive in time.

Common causes on shared, WordPress and VPS hosting

The usual causes are:

  • Too many PHP requests at once. Each page view needs a PHP worker, a process that builds the page. Only a limited number can run in parallel. When all are busy, new visitors wait and may see an error.
  • Slow plugins, queries or imports. A heavy search, a badly built plugin or a big product import can hold a worker so long that the gateway gives up, which shows as a 504.
  • A stopped web server or PHP-FPM. PHP-FPM is the service that runs PHP for the web server. If it stops, the web server has nobody to pass the request to, and you get a 502.
  • Maintenance. While it updates, WordPress shows “Briefly unavailable for scheduled maintenance” with a 503. If an update breaks off, a leftover .maintenance file in the main WordPress folder (next to wp-config.php) can keep the message up. Delete that file.
  • Traffic spikes and bots. A sale, a shared post or aggressive crawlers can use up every worker in minutes.

Is the error from Cloudflare or your own server?

Cloudflare sits in front of every site we host, so first find out who is talking. Look at the error page:

  • A Cloudflare-branded 502 or 504 means your server sent the error and Cloudflare passed it on.
  • A plain 502 or 504 page without branding usually comes from Cloudflare itself.
  • A Cloudflare page with a code in the 520s means Cloudflare works but could not get a good answer from your server.
CodeWhat it usually means
520Your server sent back an empty or unexpected answer, often after PHP crashed.
521Your server refused the connection. The web server may be stopped, or a firewall is blocking Cloudflare.
522Cloudflare could not reach your server in time. It may be overloaded or offline.
524Cloudflare connected, but your server took too long to send the page. A slow script is the usual cause.

Cloudflare error pages also show a Ray ID, usually at the bottom. It identifies the request, so add it to your ticket. Cloudflare's guide to 5xx errors explains every code.

A checklist for site owners

  1. Reload. Wait a minute and try again. Many of these errors last only seconds.
  2. Check whether it is only you. Open the site on your phone over mobile data, not office Wi-Fi. If it works there, the problem may be your network.
  3. Read the logs. In Plesk, open Websites & Domains, pick your site and click Logs. Look at entries from the time the error started. Words like “timeout” or “max_children” (all PHP workers busy) point to the cause.
  4. Disable the last plugin you added. If the dashboard will not load, rename that plugin's folder inside wp-content/plugins using the file manager, then reload.
  5. Check for traffic spikes. Plesk shows your site's traffic under Statistics. If the errors come back every time you get busy, the site may have outgrown its plan.

Our knowledge base has more step-by-step help.

Quick steps for VPS owners

With root access (full administrator rights) you can check the server yourself. Connect over SSH, a secure remote login, and check the services your server uses:

systemctl status nginx
systemctl status apache2
systemctl status php8.3-fpm

Names vary. On AlmaLinux, Apache is httpd, with logs in /var/log/httpd/, and PHP is php-fpm. On Ubuntu and Debian, the PHP service includes its version number. If a service shows “failed” or “inactive”, read its log first to find out why it stopped, then restart it.

Then read the newest lines of the error logs:

tail -n 50 /var/log/nginx/error.log
tail -n 50 /var/log/apache2/error.log
journalctl -u php8.3-fpm -n 50

“connect() failed” means PHP-FPM is down or nginx is pointing at the wrong place. “upstream timed out” means a script is too slow. “pm.max_children” means all PHP workers are busy. Run free -h to see whether the server is short of memory.

When to contact your host, and what to write

Write to us if the error lasts more than a few minutes, affects more than one site, or the logs point to the server rather than your site. Check the status page first, because we publish incidents there.

A good ticket includes:

  • the domain and the exact address that fails;
  • the error code, a screenshot and the Ray ID;
  • the date and time it started;
  • what changed just before, such as an update or import;
  • what you already tried.

An accountant in Tirana who writes “504 on the invoices page since 14:10, Ray ID attached, started after a plugin update” gets help faster than one who writes “site down”. You can reach us by ticket, email or phone, and we answer tickets in 17 languages, including Albanian. See our contact page.

Fewer gateway errors with Zebra Hosting

Every site we host sits behind Cloudflare's CDN, which keeps copies of your site close to visitors, and its DDoS filtering, which stops attack traffic before it reaches the server. Shared and WordPress plans include Plesk, so your logs are a few clicks away. If your site outgrows shared hosting, a VPS gives you your own resources and full root access.