How to Fix 502 Bad Gateway Error (For Visitors & Website Owners)
A 502 Bad Gateway indicates an edge proxy (Cloudflare, Nginx, AWS ALB) received an invalid response from your upstream origin application server. For visitors: hard refresh with Ctrl+F5 or clear DNS cache. For site owners: inspect upstream PHP-FPM/Node.js process status, restart crashed web workers, and check Nginx error logs at /var/log/nginx/error.log.
Live Website Status & Uptime Checker
Real-time edge HTTP/HTTPS reachability probe measuring status codes, TTFB latency in milliseconds, server headers, and final resolution state.
| Parameter / Metric | Exact Value / Standard | Notes & Operational Context |
|---|---|---|
| HTTP Status Code | 502 Bad Gateway | Server error response |
| Failure Domain | Between reverse proxy and origin application | Edge proxy reachable; backend dead |
| Cloudflare Indicator | Error 502: Bad Gateway Host | Origin server dropped connection |
| Default Nginx Error Log | /var/log/nginx/error.log | Inspect for connection refused |
| Fast Visitor Fix | Ctrl + F5 (Hard cache refresh) | Forces bypass of local stale browser cache |
1. What Causes a 502 Bad Gateway Under the Hood?
When you visit a website, your request hits an edge reverse proxy (such as Cloudflare, Nginx, or an AWS Load Balancer). The proxy forwards the request internally to the application server (such as Node.js on port 3000 or PHP-FPM via a UNIX socket).
If the application server crashes, runs out of memory, or fails to respond before the proxy's read timeout expires, the reverse proxy returns an HTTP 502 Bad Gateway error.
2. Server Admin Fix: 4-Step Origin Diagnostics
Log into your server via SSH and execute the following commands:
- Check Memory Pressure: Run `free -m` to see if the Linux Out-Of-Memory (OOM) killer terminated your application worker.
- Verify Upstream Port: Verify that your Node.js or Docker container is actively bound to the port specified in your Nginx proxy_pass directive (e.g. `http://127.0.0.1:3000`).
- Increase Proxy Timeouts: If your backend performs heavy calculations, increase `proxy_read_timeout` from 60s to 120s in your Nginx server block.
# Check upstream application status (Node.js PM2 or systemd)
sudo systemctl status nginx
sudo systemctl status php-fpm
pm2 status
# Inspect recent proxy connection drops
sudo tail -n 50 /var/log/nginx/error.logFrequently Asked Questions
Is a 502 error caused by my internet connection?
Rarely. 502 Bad Gateway is almost always a server-side failure. However, a corrupt local DNS cache can route requests to an outdated IP address.
What is the difference between a 502 and 504 error?
A 502 Bad Gateway means the upstream server sent an invalid or corrupt response. A 504 Gateway Timeout means the upstream server took too long and never responded at all.
Need 99.99% Uptime for Your Website?
Deploy ultra-low latency NVMe servers with automated Cloudflare DDoS mitigation, automated backups, and 1-click WordPress staging.
* FTC Disclosure: We may receive affiliate compensation when you subscribe via our partner links at no extra cost to you.
Recommended Diagnostic Tools
Live Website Status & Uptime Checker
Real-time edge HTTP/HTTPS reachability probe measuring status codes, TTFB latency in milliseconds, server headers, and final resolution state.
HTTP Response Headers Inspector & Security Audit
Inspect live HTTP response headers and perform an automated security audit on HSTS, CSP, X-Frame-Options, X-Content-Type-Options, and Referrer-Policy.
DNS-over-HTTPS (DoH) Multi-Record Explorer
Query real DNS records (A, AAAA, CNAME, MX, TXT, NS) with TTLs using Google and Cloudflare DNS-over-HTTPS JSON resolvers.
SSL / TLS Certificate Chain & Expiry Auditor
Execute a real TLS handshake probe to extract certificate subject, issuer, issue date, expiry date, days remaining, SANs, and cipher protocol.