Connection refused for when using node.js app (port 3000) with nginx reverse-proxy

Hello everyone,

I tried to setup docker-compose with two containers: a site 1 (Nuxt.js app) and the Nginx reverse-proxy to reach the site at

When I access, I get the following error:

proxy_1  | 2018/07/13 09:50:12 [error] 5#5: *9 connect() failed (111: Connection refused) while connecting to upstream, client:, server:, request: "GET / HTTP/1.1", upstream: "", host: ""

Here is the docker-compose.yml configuration:

version: "3"
    image:  # (Nuxt.js app)
      - webnet
      - "3000"
      - "3000:3000"
    command: "npm run start"
    image: nginx:latest
      - ./nginx.template:/etc/nginx/conf.d/nginx.template
      - "80:80"
      - webnet
      - web
    command: /bin/bash -c "envsubst '$$NGINX_HOST $$NGINX_PORT' < /etc/nginx/conf.d/nginx.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"

Here is the nginx.template configuration :

server {
    listen 80;
    location / {
        proxy_pass http://web:3000;
	proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Here is the output of docker-compose up:

Creating preprod-site_web_1 ... done
Creating preprod-site_nginx_1 ... done
Attaching to preprod-site_web_1, preprod-site_nginx_1
web_1    |
web_1    | > app_test@1.0.0 start /
web_1    | > nuxt start
web_1    |
web_1    | [10:03:21] [NUXT:AXIOS] baseURL: http://localhost:3000/
web_1    | [10:03:21] [NUXT:AXIOS] browserBaseURL: http://localhost:3000/
web_1    |
web_1    |  OPEN  http://localhost:3000
web_1    |

Here is the /etc/hosts XXX XXX  # I have hidden the hostname localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

I tried a lot of other configurations but I always ended up with this error.

What is wrong ? Is there a restriction on the port 3000 somehow ?

I checked that my app was running in the container called web by checking the output of curl localhost:3000 inside the container.

Thank you in advance, Samuel

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

For me I had a network error issue. My server didnt have the proper host of

'localhost' or better yet '' 

and so even though I could plug the domain name and the port into my browser and even curl and get some data back, internally my client side node app didnt seem to be able to read the correct web address when I said the host to



netstat -plnt

to see what ports are actually being listened to and try using ‘’ for all hosts


What I could suggest is checking if your containers are part of the new network:

docker network inspect webnet

Then test the connection:

docker exec -ti nginx ping web

Regards, Bobby