title: Connection Refused while connecting to upstream (nginx + uwsgi + django)
body: <p>I am trying to create a multi-container setup with an Nginx reverse proxy in front of the Django(with uwsgi) apps - <code>auth</code> and <code>shortner</code></p>
  <p>I am getting the following error when I am trying to do GET <a href="https://0.0.0.0:80/auth/" rel="nofollow noreferrer">0.0.0.0:80/auth/</a> -</p>
  <pre><code>docker_djangoapps_nginx-nginx-1     | 2022/05/08 15:56:06 [error] 23#23: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.176.1, server: , request: &quot;GET /auth/ HTTP/1.1&quot;, upstream: &quot;uwsgi://0.0.0.0:8080&quot;, host: &quot;0.0.0.0:80&quot;
  docker_djangoapps_nginx-nginx-1     | 192.168.176.1 - - [08/May/2022:15:56:06 +0000] &quot;GET /auth/ HTTP/1.1&quot; 502 157 &quot;-&quot; &quot;PostmanRuntime/7.29.0&quot; &quot;-&quot;
  </code></pre>
  <p>I am unable to understand why uwsgi is giving a connection refused when nginx is trying to connect upstream?</p>
  <p>My project directory looks like this -</p>
  <pre><code>.
  ├── README.md
  ├── auth
  │   ├── Dockerfile
  │   ├── app_auth
  │   │   ├── __init__.py
  │   │   ├── apps.py
  │   │   ├── tests.py
  │   │   ├── urls.py
  │   │   └── views.py
  │   ├── manage.py
  │   ├── requirements.txt
  │   └── service
  │       ├── __init__.py
  │       ├── asgi.py
  │       ├── settings.py
  │       ├── urls.py
  │       └── wsgi.py
  ├── docker-compose.yaml
  ├── nginx
  │   ├── Dockerfile
  │   └── nginx.conf
  └── shortner
      ├── Dockerfile
      ├── app_shortner
      │   ├── __init__.py
      │   ├── admin.py
      │   ├── apps.py
      │   ├── models.py
      │   ├── tests.py
      │   ├── urls.py
      │   └── views.py
      ├── manage.py
      ├── requirements.txt
      └── service
          ├── __init__.py
          ├── asgi.py
          ├── settings.py
          ├── urls.py
          └── wsgi.py
  </code></pre>
  <p>My docker-compose.yml file for the project is -</p>
  <pre class="lang-yaml prettyprint-override"><code>version: '3.8'
  
  services:
    auth:
      build: ./auth
      command: uwsgi --http :8080 --module=service.wsgi:application
      #command: [sh, -c, &quot;python manage.py makemigrations &amp;&amp; python manage.py migrate &amp;&amp; python manage.py runserver 0.0.0.0:8000&quot;]
      expose:
        - 8080
      env_file:
        - ./.env.dev
  
    shortner:
      build: ./shortner
      command: uwsgi --http :8081 --module=service.wsgi:application
      #[sh, -c, &quot;python manage.py makemigrations &amp;&amp; python manage.py migrate --run-syncdb &amp;&amp; python manage.py runserver 0.0.0.0:8000&quot;]
      expose:
        - 8081
      env_file:
        - ./.env.dev
    
    nginx:
      build: ./nginx
      ports:
        - 80:80
      depends_on:
        - auth
        - shortner
  </code></pre>
  <p>DockerFile for Nginx reverse proxy -</p>
  <pre><code>FROM nginx:stable-alpine
  RUN rm /etc/nginx/conf.d/default.conf
  COPY nginx.conf /etc/nginx/conf.d/
  </code></pre>
  <p>This is the nginx.conf file (in the above Dockerfile) -</p>
  <pre><code>server {
      listen       0.0.0.0:80;
      location /auth/ {
          uwsgi_pass 0.0.0.0:8080;
          include /etc/nginx/uwsgi_params;
      }
      location /short/ {
          uwsgi_pass 0.0.0.0:8081;
          include /etc/nginx/uwsgi_params;
      }
  }
  </code></pre>
  <p>Dockerfile for my Django apps(both) is -</p>
  <pre><code>FROM python:3.10-alpine
  RUN apk add build-base
  RUN apk add linux-headers
  
  WORKDIR /usr/src/app
  
  ENV PYTHONDONTWRITEBYTECODE 1
  ENV PYTHONUNBUFFERED 1
  
  RUN pip install --upgrade pip
  COPY ./requirements.txt .
  RUN pip install -r requirements.txt
  
  COPY . .
  </code></pre>
  <p>Environment file for the django apps (as referenced in the docker-compose.yml)  has the following line -</p>
  <pre><code>DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] 0.0.0.0
  </code></pre>