Nginx connection refused, when trying to connect to node app as reverse proxy

I trying to build a webapp with docker containers and I am getting connection refused when trying to run Nginx as a reverse proxy to my node app. I am not sure if it is a nginx server config issue or a docker-compose config issue.

[error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client:, server:, request: "GET / HTTP/1.1", upstream: "", host: ""

I get this error when hitting, the weird thing is that my app works when the port number is referenced, so runs the app.

  • Backup stateful docker volume
  • Docker MGT Development Environment and Mailbag
  • LDAP-Server with official docker support
  • Why systemd process running in docker container with PID 1 not forwarding SIGTERM to child processes on docker stop
  • How to run a command after creating a container using yml file
  • Running Gatling from docker-compose
  • My nginx server config:

    server {
        listen       80;
        port_in_redirect off;
        autoindex on;
        location / {
            proxy_redirect off;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;

    My Docker Compose File: (There might be some redundant things in here)

    version: "2"
        build: ./nginx
          - "80:80"
          - app
          - app
          context: .
          dockerfile: DockerFile
          - "7770:7770"
          - mongo
          - mongo
        image: mongo
          - "27017:27017"
          - mongodata
          - mongodata
        image: tianon/true
          - /data/db

    My Node Dockerfile:

    FROM node:latest
    ADD package.json /tmp/package.json
    RUN cd /tmp && npm install
    RUN mkdir -p /opt/app && cp -a /tmp/node_modules /opt/app/
    WORKDIR /opt/app
    ADD . /opt/app
    EXPOSE 7770
    CMD ["npm", "start"]

    My ngnix Dockerfile

    FROM nginx:1.10
    COPY default.conf /etc/nginx/conf.d/default.conf

    On npm start this will run:

    app.get('*', function(req, res) {
      res.sendFile(path.join(__dirname, 'index.html'));
    app.listen(7770, function(err) {
      if (err) {
      console.log('Listening at http://localhost:7770');

    This is my first run at docker, so I may have muddled up a few things. Also I am pointing to in /private/etc/hosts.

  • Unable to use *build* object in docker-compose
  • How to remote access(from out net) to jupyter notebook running on docker on ubuntu server
  • Port forward for mysql replication (within docker)
  • If images in Docker are untagged, are they used at all or just orphans?
  • Docker private registry can't find tags when pulling
  • “tag latest not found” on docker pull with private registry
  • 2 Solutions collect form web for “Nginx connection refused, when trying to connect to node app as reverse proxy”


    First of all, you need to remember each container has its own network stack, so you cannot use localhost inside the container to reach a service running in the docker host.

    For this specific project, you will need to point the proxy_pass directive in your Nginx server config to a value what reach the app container. Something like:

    proxy_pass http://app:7770;

    You will need to do right that because in docker-compose context your container name will be mapped to an internal DNS entry. With that, you will not need to publish 7770 of the app container to the outside world and if your MongoBD will be accessed just by your app container, you will not need to publish the 27017 port either.

    If you want to route traffic from nginx to app you have to use ip address or dns of the app container on proxy_pass. With Docker Compose services can discover each other with service names, so change in nginx conf

    proxy_pass http://app:7770;

    You don’t need to publish port 7770 to outside world. Also for mongo you don’t need to publish 27017 port.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.