Nothing is listening at the address the proxy is using
CommonThe upstream process is not running, is still starting, or is listening somewhere other than where the proxy is looking. The proxy's connection is actively refused, which is a fast failure rather than a hang — the 502 arrives immediately.
Confirm
sudo tail -50 /var/log/nginx/error.log | grep -iE 'connect\(\) (to [^ ]+ )?failed'
(111: Connection refused). That is the kernel saying nothing holds the port, which is unambiguous — the address in the message is where the proxy tried.
Fix
- Confirm the upstream is running and listening on exactly the address in the proxy config, with
ss -tlnp | grep <port>. - Check the bind address, not just the port. A process on
127.0.0.1:3000is unreachable from a proxy in a different container or on another host, even though the port is correct. - If the upstream is a container, check the proxy is using the container name and container port rather than a published host port.
ss -tlnp | grep ':3000' # is anything listening, and on what address? curl -sv http://127.0.0.1:3000/ -o /dev/null # from the proxy's own host
Run the curl from wherever the proxy runs. Reachability from your laptop proves nothing about reachability from the proxy.