API Error 502 Bad Gateway Alert
Detect proxy and load balancer issues on your APIs.
The 502 Bad Gateway error occurs when an intermediary server (proxy, load balancer) receives an invalid response from the upstream server. The problem lies between your infrastructure and the application.
These errors can be intermittent and difficult to diagnose without proper monitoring.
Symptoms
- HTTP 502 code: explicit Bad Gateway in the response.
- Sporadic errors: often intermittent, some requests succeed.
- Abnormal response times: high latency before the 502 error.
Common Causes
- Backend crash: the upstream application crashed or stopped responding.
- Backend timeout: the backend takes too long to respond.
- Proxy configuration: Nginx or HAProxy misconfigured.
- Exhausted worker pool: PHP-FPM or application pool saturated.
Automate with MoniTao
- 502 monitoring: alert specifically on 502 codes.
- Upstream monitoring: also monitor the backend directly.
Frequently Asked Questions
How to differentiate 502 from 504?
502 = invalid response from backend. 504 = no response from backend (timeout).
Does the 502 come from Nginx or the backend?
Check both Nginx logs AND backend logs. Nginx 502 is often caused by PHP-FPM.
How to avoid 502s?
Increase timeouts, add workers, optimize the backend.
Does MoniTao distinguish 502 and 504?
Yes, you can create specific alert rules for each error code.
Useful Links
Ready to Sleep Soundly?
Start free, no credit card required.