Docker nginx service can't communicate with Django service and returning Bad Request 400

My nginx Docker container can't seem to communicate with my Django WSGI app container. It works locally but when I deploy it to Linode I get Bad Request (400)

Project Structure

Project
─ Dockerfile
─ docker-compose.yml
─ entrypoint.sh

└── app
 ── wsgi.py
 ── settings.py
 ── urls.py
 ── <other django apps>

└── nginx
 ── Dockerfile
 ── nginx.conf

docker-compose.yml:

version: '3.3'

services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    command: gunicorn app.wsgi:application --bind 0.0.0.0:8000
    expose:
      - 8000
    env_file:
      - ./.env
    depends_on:
      - db
  db:
    image: postgres:12.0-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    env_file:
      - ./.env.db
  nginx:
    build: ./nginx
    volumes:
      - static_volume:/var/www/app/staticfiles
      - media_volume:/var/www/app/mediafiles
    ports:
      - 80:80
    depends_on:
      - web


volumes:
  postgres_data:

nginx/Dockerfile

FROM nginx:1.17.4-alpine

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d

nginx/nginx.conf

upstream polls_django {
    server web:8000;
}

server {

    listen 80;

    location / {
        proxy_pass http://polls_django;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }

}

Clues:

  1. Locally: I can visit my app at localhost just fine. However, I noticed that I will get Bad Request (400) when trying to visit 0.0.0.0.

  2. Linode: When I visit the IP address of my Linode I get Bad Request (400). Looking at my nginx container's error logs, something I noticed is this entry:

2022/11/28 01:08:51 [info] 7#7: *2 client timed out (110: Operation timed out) while waiting for request, client: 12.34.56.78, server: 0.0.0.0:80

It seems that the request to the server is never actually hitting the WSGI app

  1. Linode: I got a shell into my nginx container running docker exec -it nginx /bin/sh and noticed that I could call curl 127.0.0.1 and get the expected response. I feel this means there must be something wrong with my nginx.conf then

Anyone have any clues that I can try out?

For reference: I went through this guide (https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/) Code I'm running: https://github.com/drivelous/docker-ubuntu18.04-django3.0.2

Back to Top