debugMajor
Nginx 502 Bad Gateway — upstream connection issues
Viewed 0 times
502 Bad Gatewayupstreamproxy_passproxy_read_timeoutbuffer sizeUnix socket
linuxdocker
Error Messages
Problem
Nginx returns 502 Bad Gateway. The upstream application is running but Nginx cannot connect to it. Intermittent or consistent depending on load.
Solution
502 means Nginx got an invalid response from upstream. Common causes: (1) Upstream crashed — check its logs. (2) Wrong upstream port — verify proxy_pass matches listen port. (3) Socket permissions — for Unix sockets, ensure Nginx user can read/write. (4) Upstream timeout — increase proxy_read_timeout and proxy_connect_timeout. (5) Buffer too small — increase proxy_buffer_size for large headers. Check: tail -f /var/log/nginx/error.log.
Why
Nginx acts as a reverse proxy. 502 means the proxy layer worked but backend communication failed. Unlike 504 (timeout), 502 indicates the connection was made but the response was invalid.
Revisions (0)
No revisions yet.