A
A
Alexander Bondarenko2021-09-14 12:45:43
Django
Alexander Bondarenko, 2021-09-14 12:45:43

How to run multiple sites on the same server using docker and nginx?

Hello everyone, I'm trying to run two sites on django on the same server under different ip, an error occurs that the port is busy, I fixed the ports, but the site does not start. Where is the error please? When I click on ip I get the error This site can't be reached
.env

#Django
# Should be one of dev, prod
MODE=prod
PORT=8008

#postgres
DB_NAME=xxx
DB_USER=xxx
DB_HOST=xxx
DB_PASSWORD=xxxx
DB_PORT=5432
POSTGRES_PASSWORD=mysecretpassword

#WSGI
WSGI_PORT=8008
WSGI_WORKERS=4
WSGI_LOG_LEVEL=debug

# Celery
CELERY_NUM_WORKERS=2

# Email
EMAIL_HOST_USER=xxxx
EMAIL_HOST_PASSWORD=xxxx

version: '3'

services:

  backend:
    build: ./
    container_name: site_container
    restart: always
    command: ./commands/start_server.sh
    ports:
      - "${PORT}:${WSGI_PORT}"
    volumes:
      - ./src:/srv/project/src
      - ./commands:/srv/project/commands
      - static_content:/var/www/site
    env_file:
      - .env
    depends_on:
      - postgres

  postgres:
    image: postgres:12
    volumes:
      - pg_data:/var/lib/postgresql/data
    env_file:
      - .env
#    environment:
#      - DJANGO_SETTINGS_MODULE=app.settings.${MODE}

  nginx:
    image: nginx:1.19
    volumes:
      - ./nginx:/etc/nginx/conf.d
      - static_content:/var/www/site
    ports:
      - 81:80
      - 444:443
    env_file:
      - .env
    depends_on:
      - backend

volumes:
  pg_data: {}
  static_content: {}


server {
    listen 80 default_server;

    server_name 183.22.332.12;

    location /static/ {
        root /var/www/site;
    }

    location /media/ {
        root /var/www/site;
    }

    location / {
        proxy_set_header Host $host;
        proxy_pass http://backend:8010;
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question