Why Nginx is Serving my django app in port 8000 instead of 80?

i have created a app using django https://github.com/pyalz/video_app . I run this application now using django compose build django compose up .

When i open http://0.0.0.0:8000 its coming with static files. when i open http://0.0.0.0:80 its not showing me static files

**Docker compose **

version: '3.7'

services:
  django_gunicorn:
    volumes:
      - static:/static
    env_file:
      - .env
    build:
      context: .
    ports:
      - "8000:8000"
  nginx:
    build: ./nginx
    volumes:
      - static:/static
    ports:
      - "80:80"
    depends_on:
      - django_gunicorn

volumes:
  static:

Docker File

FROM python:3.10.0-alpine

RUN pip install --upgrade pip

COPY ./requirements.txt .
RUN pip install -r requirements.txt

COPY ./video_app /app

WORKDIR /app

COPY ./entrypoint.sh /
ENTRYPOINT ["sh", "/entrypoint.sh"]

Entry.sh

#!/bin/sh
python manage.py migrate --no-input
python manage.py collectstatic --no-input

DJANGO_SUPERUSER_PASSWORD=$SUPER_USER_PASSWORD python manage.py createsuperuser --username $SUPER_USER_NAME --email $SUPER_USER_EMAIL --noinput

gunicorn video_app.wsgi:application --bind 0.0.0.0:8000

NGINX Docker file

FROM nginx:1.19.0-alpine

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

Default.conf

upstream django {
    server django_gunicorn:8000;
}

server {
    listen 80;

    location / {
        proxy_pass http://django;
    }

    location /static/ {
        alias /static/;
    }
}

enter image description here enter image description here

Could you please help me resolve this issue

Your default.conf file only lists Django's docker address, but it doesn't list the port, so it defaulted to port 80. Change it to this:

server {
    listen 80;

    location / {
        proxy_pass http://django:8000;
    }

    location /static/ {
        alias /static/;
    }
}
Back to Top