title: Connection refused while connecting to upstream when using nginx as reverse proxy
body: <p>The setup is as follows: I have a Gunicorn/Django app running on <code>0.0.0.0:8000</code> that is accessible via the browser. To serve static files I am running nginx as a reverse proxy. <code>/etc/nginx/nginx.conf</code> is configured to forward requests as follows: </p>
  
  <pre><code>server {
      location /static/ {
          alias /data/www/;
      }
  
  
      # Proxying the connections
      location / {
          proxy_set_header   Host $host;
          proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
  
          proxy_redirect     off;
          proxy_pass         http://0.0.0.0:8000;
      }
  }
  </code></pre>
  
  <p>and my <code>docker-compose.yml</code> file is as follows: </p>
  
  <pre><code>version: '3.3'
  
  services:
    web:
      restart: always
      build: ./web
      expose:
        - "8000"
      ports:
        - "8000:8000"
      volumes:
        - staticdata:/usr/src/app/static_files
      command: gunicorn wsgi:application --workers 2 --bind 0.0.0.0:8000
      depends_on:
        - postgres
  
    nginx:
      restart: always
      build: ./nginx
      ports:
        - "80:80"
        - "443:443"
      volumes:
        - staticdata:/data/www
      depends_on:
        - web
  
    postgres:
      image: postgres:9.2
      restart: always
      volumes:
        - pgdata:/var/lib/postgresql/data
      ports:
        - "5432:5432"
  
  volumes:
    staticdata:
    pgdata:
  </code></pre>
  
  <p>When I visit <code>0.0.0.0:8000</code> via the browser the application works fine (albeit without serving static files), but when I visit <code>127.0.0.1:80</code> I get the following error: </p>
  
  <pre><code>nginx_1     | 2017/09/17 13:59:46 [error] 6#6: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: , request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:8000/", host: "127.0.0.1"
  </code></pre>
  
  <p>I know that this error indicates that the server running on <code>0.0.0.0:8000</code> is not accepting requests, but since I can visit it via the browser I am a bit confused.</p>
  
  <p>Thank you in advance.</p>