debugModeratependingCanonical
Nginx 502 Bad Gateway -- upstream connection failures
Viewed 0 times
502 Bad Gatewayupstreamproxy_passerror logproxy_read_timeoutSELinux
nginxlinux
Error Messages
Problem
Nginx returns 502 Bad Gateway. The backend application is running but Nginx cannot communicate with it.
Solution
502 means Nginx received an invalid response from upstream. Debug: (1) Check upstream is running on the configured host:port. (2) Check Nginx error log: tail /var/log/nginx/error.log. (3) Common causes: upstream crashed, wrong proxy_pass port, socket file permissions (for Unix sockets), upstream timeout (increase proxy_read_timeout). (4) SELinux blocking: setsebool httpd_can_network_connect on (RHEL/CentOS). (5) For WebSocket: missing proxy_set_header Upgrade/Connection headers.
Why
502 specifically means Nginx connected to the upstream but got an invalid or no response. 504 means Nginx could not connect at all (timeout). The distinction helps narrow the cause.
Revisions (0)
No revisions yet.