Запуск нескольких проектов django с помощью docker и nginx

Я пытаюсь сделать следующее.

  • У меня есть 3 django проекта (НЕ приложения) (может быть больше).
  • Proj1: На порту 8000, Proj2: 8001, и Proj3:8002

Вот чего я пытаюсь достичь:

Пользователь посещает : localhost:8000

Все ссылки под Pr1: Ответить

Посещение пользователя: localhost:8000/Pr2

Все ссылки под Pr2: Отвечать

Посещение пользователя: localhost:8000/Pr3

Все ссылки под Pr3: Отвечать

Goal: Проект 1 запущен с помощью Docker и Nginx. Теперь у меня есть 2 новых проекта, которые нужно интегрировать. Каждый новый подпроект должен быть доступен только через один основной порт (8000). Но внутри запрос направляется на нужный порт подпроекта.

Почему эта цель: Достичь структуры в стиле микросервиса. Подпроекты (2 & 3) могут быть достигнуты только после аутентификации через Proj1.

Что я пробовал: Честно говоря, нет четкого представления, с чего начать.

  • Добавлены новые проекты в docker-compose... все они работают при посещении собственного порта (localhost:8001/Prj2) ..

  • Вместе с nginx, попробовал добавить новый сервер. Никакого эффекта:

      server {
          listen 8001;
    
          location / {
              proxy_pass         http://web_socket:8080;
              proxy_redirect     off;
          }
      }
    

Если у вас установлен "nginx", то вы можете просто создать два файла (site1.com.conf, site2.com.conf) в следующем каталоге: "/etc/nginx/sites-enabled/". Затем добавьте в эти файлы следующие коды:
site1.com.conf

# the upstream component nginx needs to connect to
upstream site1.com {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server 127.0.0.1:49151; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name site1.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /var/www/site1.com/src/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /var/www/site1.com/src/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  site1;
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
    }
}

site2.com.conf

# the upstream component nginx needs to connect to
upstream site2.com {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server 127.0.0.1:49152; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name site2.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /var/www/site2.com/src/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /var/www/site2.com/src/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  site2;
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
    }
}

После сохранения файлов перезапустите uwsgi (установите, если он не установлен) и nginx
. service uwsgi restart
sudo /etc/init.d/nginx restart

Вернуться на верх