nginx & nodejs: connect() failed (111: Connection refused) while connecting to upstream
From your docker-compose.yml you are exposing port 80 from the nginx container to port 80 outside the container, but you are exposing port 8543 to a random port. When you tell nginx to look for 127.0.0.1:8543 it won't find that port in the host.
You are already linking both containers together, you don't need to expose port 8543 to the host in order to access if from nginx. All you need to do is tell it to access the right host:
# Nodejs APIupstream api { server node:8543;}
This happens because when you link containers docker set the host in /etc/hosts. You can check it:
docker exec -ti nginx bashcat /etc/hosts
Of course, it should work if you expose 8543:
nginx:build: nginxports: - "80:80"link: nodenode:build: nodeports: - "8543:8543"environment: - HOST=127.0.0.1 - PORT=8543
More on docker networking: https://docs.docker.com/articles/networking/