HTTP 502 Bad Gateway
Status code 502 · Class 5xx
Bad Gateway
Also searched as: error 502, HTTP 502, 502 bad gateway, nginx 502
What it means
502 Bad Gateway means a server acting as a gateway or proxy (nginx, a CDN such as Cloudflare, a load balancer) got an invalid response, or no response, from the upstream server behind it. The front end is up; the application behind it is failing.
Applies to: All browsers, nginx, Apache, Cloudflare, AWS ALB
How to fix HTTP 502 Bad Gateway
- Reload after a minute; many 502s come from a backend restart or deployment
- Try another network or device to rule out a broken proxy on your side
- Clear cache and cookies for the site
- If you own the site: check that the upstream service is running ('systemctl status php8.2-fpm', 'pm2 status', 'docker ps')
- If you own the site: read nginx error.log for 'connect() failed', 'upstream prematurely closed' or socket permission errors and fix the upstream address or socket
- If you own the site: check for out-of-memory kills with 'dmesg | grep -i kill' and raise worker limits or memory as needed
- If you own the site behind Cloudflare: make sure the origin accepts Cloudflare's IP ranges and responds on the expected port and protocol
Why it happens
The proxy could not get a valid HTTP response from the upstream: the backend process is down or crashed, the socket path or port is wrong, the backend closes connections early, or a firewall blocks proxy-to-origin traffic.
FAQ
Is a 502 Bad Gateway error my internet?
Rarely. It almost always means the website's backend is down or misconfigured. Test from mobile data to be sure.
What is the difference between 502 and 504?
502 means the upstream sent a bad response or refused the connection. 504 means the upstream did not answer in time.
Related errors
Source: IANA HTTP Status Code Registry · fixes written and reviewed by the editors (see our editorial policy)
Last updated: