Find where the request failed before increasing timeouts. A 502 often points to failed upstream communication; a 504 often points to an upstream wait that expired. Logs distinguish the actual failure.
Example: the application is not listening
Suppose an error-log excerpt says:
connect() failed (111: Connection refused) while connecting to upstream
upstream: "http://127.0.0.1:3000/products"
Nginx tried to connect to port 3000 and was refused. Check whether the application is running and listening on that address. From Nginx's own machine or container, test . Inside a container, that address refers to the container itself, not automatically to another application's container.
