title: Nginx connection refused, when trying to connect to node app as reverse proxy
body: <p>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.</p>
  
  <pre><code>[error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.20.0.1, server: foo.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:7770/", host: "foo.com"
  </code></pre>
  
  <p>I get this error when hitting foo.com, the weird thing is that my app works when the port number is referenced, so foo.com:7770 runs the app.</p>
  
  <p>My nginx server config:</p>
  
  <pre><code>server {
      listen       80;
      server_name  foo.com;
  
      port_in_redirect off;
      autoindex on;
  
      location / {
          proxy_pass http://127.0.0.1:7770;
          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;
      }
  }
  </code></pre>
  
  <p>My Docker Compose File: (There might be some redundant things in here)</p>
  
  <pre><code>version: "2"
  services:
    nginx:
      build: ./nginx
      ports:
        - "80:80"
      depends_on:
        - app
      links:
        - app
    app:
      build:
        context: .
        dockerfile: DockerFile
      ports:
        - "7770:7770"
      links:
        - mongo
      depends_on:
        - mongo
    mongo:
      image: mongo
      ports:
        - "27017:27017"
      volumes_from:
        - mongodata
      depends_on:
        - mongodata
    mongodata:
      image: tianon/true
      volumes:
        - /data/db
  </code></pre>
  
  <p>My Node Dockerfile:</p>
  
  <pre><code>FROM node:latest
  
  ADD package.json /tmp/package.json
  RUN cd /tmp &amp;&amp; npm install
  RUN mkdir -p /opt/app &amp;&amp; cp -a /tmp/node_modules /opt/app/
  
  WORKDIR /opt/app
  ADD . /opt/app
  
  EXPOSE 7770
  
  CMD ["npm", "start"]
  </code></pre>
  
  <p>My ngnix Dockerfile</p>
  
  <pre><code>FROM nginx:1.10
  
  COPY default.conf /etc/nginx/conf.d/default.conf
  </code></pre>
  
  <p>On npm start this will run:</p>
  
  <pre><code>app.get('*', function(req, res) {
    res.sendFile(path.join(__dirname, 'index.html'));
  });
  
  app.listen(7770, function(err) {
    if (err) {
      console.log(err);
      return;
    }
  
    console.log('Listening at http://localhost:7770');
  });
  </code></pre>
  
  <p>This is my first run at docker, so I may have muddled up a few things. Also I am pointing foo.com to 127.0.0.1 in /private/etc/hosts.</p>