title: How do I run multiple sites on the same server using docker and nginx?
body: <p>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. Tell me where is the error please? Ip work, when I go to the second ip I get redirects to the first site. All settings were specified for the second site. At the end, I added the nginx setting of the first site</p>
  <p>This is the second docker-compose file and its settings. I would be very grateful for your help</p>
  <p>.env</p>
  <pre><code>#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
  </code></pre>
  <p>docker-compose.yml</p>
  <pre><code>version: '3'
  
  services:
  
    backend:
      build: ./
      container_name: site_container
      restart: always
      command: ./commands/start_server.sh
      ports:
        - &quot;${PORT}:${WSGI_PORT}&quot;
      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: {}
  </code></pre>
  <p>default.conf</p>
  <pre><code>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;
      }
  }
  </code></pre>
  <p>default.conf for first site</p>
  <pre><code>server {
      #listen 80 default_server;
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
  
      server_name site1 ip_site1;
  
      ssl_certificate /etc/letsencrypt/live/site1/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/site1/privkey.pem;
      ssl_trusted_certificate /etc/letsencrypt/live/site1/chain.pem;
  
      location /static/ {
          root /var/www/artads;
      }
  
      location /media/ {
          root /var/www/artads;
      }
  
      location / {
          proxy_set_header Host $host;
          proxy_pass http://backend:8008;
      }
  }
  
  server {
      listen 80 default_server;
  
      server_name ip_site2 site2;
  
      location /static/ {
          root /var/www/gdr_mr;
      }
  
      location /media/ {
          root /var/www/gdr_mr;
      }
  
      location / {
          proxy_set_header Host $host;
          proxy_pass http://backend:8013;
      }
  }
  
  server {
          listen 80;
          listen [::]:80;
  
          server_name www.site1 site1;
  
          location / {
                  return 301 https://site1$request_uri;
          }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/JEIQb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/JEIQb.png" alt="" /></a></p>