Nginx support multiple hostnames

I am working on my django + nginx + docker-compose project I want to access my site via ip and mysite.com

Problem -- ip url is working, but mysite.com returns error:

403 Forbidden Nginx

My code - docker-compose.yml

services:
  django:
    build: ./project # path to Dockerfile
    command: sh -c " 
      sleep 3 && gunicorn --bind 0.0.0.0:8000 core_app.wsgi"
    ...
    expose:
      - 8000
    env_file:
      - ./.env
    depends_on:
      - db

  nginx:
    image: nginx:1.19.8-alpine
    depends_on: 
      - django
    env_file:
      - ./.env
    ports: 
      - "80:80"
    volumes:
      - ./project/nginx-conf.d/:/etc/nginx/conf.d
      ...

nginx-conf.conf

upstream app {
    server django:8000;
}

server {
    listen 80;
    server_name 127.0.0.1 mysite.com www.mysite.com;

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

    location /static/ {
        alias /var/www/html/static/;
    }
}

Value of proxy_pass is incorrect.

When you're referencing an upstream group, you've to pass the name of the group to proxy_pass.

In your case, the name of upstream group is "app". So the value of proxy_pass should look like this:

proxy_pass http://app;
Back to Top