Nginx gave error 502 bad gateway when run in docker swarm

when i run nginx in swarm deploy stack it distribute to the workers node and manager node get also one service but when i browse it gave 502 bad gateway but when i run it simple docker compose its
working fine

Without sharing more information about your setup (how you deployed nginx and any related information) unfortunately you just shared the state of your swarm, but we can’t help you.

Gateway error appears when nginx can’t access the container it should forward the request to.