title: how to configure nginx for 2 different projects (2 different docker compose files)
body: <p>I have 2 projects:</p>
  <ol>
  <li><code>myapi</code> that serves all api calls</li>
  <li><code>django_web</code> that uses myapi.</li>
  </ol>
  <p>If I place them on 2 different servers - they work great (as they are completely independent) however, I wish to have them both on the same server (name it: <a href="http://www.example.com" rel="nofollow noreferrer">www.example.com</a>) but I couldn't figure our how they can both share the same nginx. I'm using docker and it complains that 0.0.0.0:443 is already in use.</p>
  <p>myapi nginx configuration:</p>
  <pre><code>upstream flask_server {    
     server flaskapp2:8000;
  }
  
  
  server {
    listen 80;
    server_name example.com;
  
   location / {
       return 301 https://$server_name$request_uri;
    }
  }
  
  server {
  listen 443 ssl;
   
  server_name example.com;
  
  location / {
      proxy_pass http://flaskapp2:8000;
      proxy_redirect     off;
      proxy_set_header   Host $host;
      proxy_set_header   X-Real-IP $remote_addr;
      proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header   X-Forwarded-Host $server_name;       
      proxy_no_cache 1;
      proxy_cache_bypass 1; 
  }
  
  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  include /etc/letsencrypt/options-ssl-nginx.conf;
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
  }
  </code></pre>
  <p>and for the django_web</p>
  <pre><code>server {
      listen 80;
      server_name example.com;
      return 301 https://$server_name$request_uri;        
  }
  
  
  server {
   client_max_body_size 20M;
   listen 443 ssl;
    server_name example.com;
  
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  
      location /static/ {
        alias /www/static/;
      }
  
      location /websocket/ {
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection &quot;upgrade&quot;;
     #proxy_pass http://$server_name:8080/websocket/my_random_number/;
     proxy_pass http://$server_name:8080;
  
   }
  
  
  
  location / {
       proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Port $server_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  
  proxy_pass http://$server_name:8080;
  
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection &quot;upgrade&quot;;
  </code></pre>
  <p>}
  }</p>
  <p>docker settings for myapi:</p>
  <pre><code>  nginx:
  image: &quot;nginx:1.13.5&quot;
  ports:
    - &quot;80:80&quot;
    - &quot;443:443&quot;
  volumes:
    - ./config/nginx/conf.d:/etc/nginx/conf.d
    - ./static:/static
    - /etc/letsencrypt:/etc/letsencrypt/ 
  restart: always
  networks:
    - my_network
  depends_on: 
    - flaskapp2
  container_name: hnginx
  </code></pre>
  <p>and for the django_web:</p>
  <pre><code>  nginx:
      restart: always
      image: &quot;nginx&quot;
      container_name: hnginx
      ports:
        - &quot;80:80&quot;
        - &quot;443:443&quot;
      volumes:
        - ./config/example:/etc/nginx/conf.d
        - ./static2:/static
        - ./media2:/media
        - .:/www
        - /etc/letsencrypt:/etc/letsencrypt/ 
        - ./config/html_pages:/usr/share/nginx/html
      networks:
        - hnetwork
  </code></pre>