Server errors (5xx)

502 Bad Gateway

A server in the middle got a bad answer from the website server.

Quick answer

Many websites have a gateway or proxy in front of the real server. A 502 means that gateway asked the real server and got no usable answer. The real server may be down, overloaded or misconfigured.

When to wait: Often yes. Short 502 errors happen during restarts and deployments.

If you are visiting the website

  1. Wait and reload Wait a minute or two, then reload the page once. Many 502 errors appear for a short moment while a server restarts or a new version goes live.
  2. Check the service's status page Big services often publish an official status page that lists known problems.
  3. Try another device or browser Open the same address on your phone or in a different browser. This shows whether the problem is your device or the website.
  4. Test without your VPN or proxy A VPN, company proxy or security tool can sit in the middle and report its own 502 when it cannot reach the site. Turn the VPN off once to compare, then turn it back on.
  5. Tell the website owner If it lasts longer than a few minutes, contact the site through another channel. Mention the exact address, the time and whether the page shows a provider name such as Cloudflare or nginx.

If you run the website

  1. Check the application server Make sure the service behind your proxy is running and listening on the expected port. On Linux with systemd, systemctl status <service> shows whether it crashed.
  2. Check the upstream address Confirm the proxy points to the right host and port, for example the proxy_pass line in nginx. A wrong port after a change is a classic cause.
  3. Read the proxy error log nginx error lines such as "connect() failed" or "upstream prematurely closed connection" tell you whether the app refused, crashed or closed the connection.
  4. Check response header size If the app sends very large headers, often many cookies, nginx treats the reply as invalid. The proxy_buffer_size setting (default 4k or 8k) decides how much header data fits.
  5. Watch memory and worker limits If the app crashes under load, check memory limits, worker counts and restart loops. Test changes with sudo nginx -t before sudo nginx -s reload.
  6. Check your hosting provider's status Your host may have a known outage. Their status page or support can confirm it.

Is it the website or me?

Almost always the website. A 502 is produced by a server between you and the website, not by your device.

The one exception is a VPN or company proxy you use yourself. If the error disappears without it, that middle point is the problem.

502, 503 and 504 compared

502: the middle server got a broken answer or none at all. 503: the server says it is not available right now. 504: the middle server waited and gave up.

All three are server-side problems. They differ in where the owner should look first.

For developers: what happens technically

A gateway or reverse proxy (a server that forwards requests to the real application) received an invalid response from its upstream. That includes refused connections, connections closed halfway and headers it cannot parse.

The proxy error log at the same second usually names which of these happened.

Common questions

Is a 502 caused by my internet connection?

Almost never. Your connection reached the middle server fine; the problem is behind it. Only a VPN or proxy you use can produce it on your side.

What is a gateway or proxy?

It is a server that stands in front of the real website and passes requests along. Many sites use one for speed and security, so you never see it until it reports a problem.

How long does a 502 usually last?

Short ones last seconds to minutes during restarts. If it stays longer, the application has likely crashed and the owner must restart or fix it.

Will clearing my browser cache help?

Rarely. The error comes from the server side. One reload after a short wait is the useful test.

Likely causes

  • Common The application server behind the proxy crashed or restarted. (Website side)
  • Sometimes The proxy points to the wrong address or port. (Website side)
  • Sometimes The server is overloaded. (Website side)

Is the website down? Check it now

One measurement point. Results explain what we saw, not a worldwide verdict.

Sources

Last reviewed: