Help for owners
My website says 502 Bad Gateway
Short answer
A 502 Bad Gateway means the server your visitors reach received an invalid answer from the application behind it. Usually that application has stopped, crashed or is unreachable. If the site works for other people, the problem may be your own network. If not, a server administrator has to look.
Does this sound like your situation?
- The browser shows 502 Bad Gateway, or a plain white nginx page.
- The site was fine a few minutes ago.
- It shows up on some pages only, or comes and goes.
- A restart seems to fix it, then it returns.
Why does this happen?
The application behind the web server is not answering
The page defines 502 as a server acting as a gateway or proxy that received an invalid response from the upstream server. In everyday terms, the front door is open but nobody answers inside.
Confirmed by developer.mozilla.org
The application crashed or ran out of memory
A site's code can stop when it runs out of memory or hits an error. The web server in front still runs, so visitors see 502.
Technical detail: nginx 502 Bad Gateway in front of a Node.js app
The two parts no longer agree on how to talk
After a change, the web server may point at an address or socket where the application is no longer listening.
Technical detail: nginx refuses to start: host not found in upstream
It can sometimes be local
The same page notes that client networking problems, VPNs or DNS settings can cause it, especially if the service works for other visitors.
Confirmed by developer.mozilla.org
What can I do about it today?
- Check from another networkOpen the site on mobile data and ask a colleague to try it. If it loads there, the issue may be your own network or a VPN.
- Wait a minute and reload onceSome 502s are short restarts. Do not keep reloading, since a flood of requests can slow a struggling server.
- Do not restart or delete things you do not knowSwitching servers off and on can lose unsaved data, and deleting files can make recovery harder.
- Collect what you knowWhen did it start? What changed shortly before: an update, a plugin, a hosting change, a traffic jump? Send that with a screenshot.
- Contact whoever runs the serverIf you have a developer or hosting support, report it now with the time and what you collected.
When should I bring someone in?
- The 502 stays more than a few minutes, or keeps coming back.
- The site takes orders or bookings and every minute counts.
- Nobody knows who runs the server.
How do I handle it?
- Look at the logs firstI read the web server and application logs for the exact minute the problem started, before I change anything.
- Take a backupBefore a production change I take a backup and note how to go back.
- Fix the proven causeI change one thing, then test it from outside, the way a visitor would.
- Add the early warningI set up a check that tells you when it starts again, so you hear about it before your customers do, and write down what happened.
The price depends on what I find, so I quote in writing after a short discovery call. Tell me what is happening and I reply within 24 hours.
What do owners ask about this?
Is my site hacked?
Usually not. A 502 is typically a stopped or unreachable application. I still check the logs for signs of an attack, because the cause matters.
Is a 502 the same as a 504?
They are related. A 504 means the server got no response in time; a 502 means it got an invalid one. Both point to the application behind the front server.
Will I lose orders or data?
A 502 itself does not delete data. Backups and a careful restart are how I keep it that way.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Found a mistake? Tell me.
For your developer: the technical fixes
502 Bad Gatewaynginx 502 Bad Gateway in front of a Node.js app502 Bad Gatewaynginx shows 502 Bad Gateway in front of a Django app on Gunicornnginx: [emerg] host not found in upstreamnginx refuses to start: host not found in upstream(13: Permission denied) while connecting to upstreamnginx cannot connect to the Gunicorn socket: Permission denied