title: Nginx TLS-SNI: Use hostname dependent SSL for HTTPS
body: <p>I need to use two different ssl certs with nginx pointing to the same app.</p>
  
  <p><a href="https://domain1.com" rel="nofollow noreferrer">https://domain1.com</a> points to 1.1.1.1<br>
  <a href="https://domain2.com" rel="nofollow noreferrer">https://domain2.com</a> points to 1.1.1.1
  .<br>
  .<br>
  .<br>
  .<br>
  <a href="https://domainN.com" rel="nofollow noreferrer">https://domainN.com</a> points to 1.1.1.1 </p>
  
  <p>Tried the following:</p>
  
  <pre><code>server {
  listen 80;
  server_name domain1.com;
  return 301 https://$host$request_uri;
  }
  
  
  
  server {
  
      listen 443 ssl;
      server_name domain1.com;
      root /app/dist;
  
      index index.html;
  
      ssl_certificate /etc/nginx/ssl/d1/certificate.crt;
      ssl_certificate_key /etc/nginx/ssl/d1/private.key;
  
      location / {
  
          try_files $uri $uri/ /index.html;
  
      }
  
  }
  
  server {
  listen 80;
  server_name domain2.com;
  return 301 https://$host$request_uri;
  }
  
  
  
  server {
  
      listen 443 ssl;
      server_name domain2.com;
      root /app/dist;
  
      index index.html;
  
      ssl_certificate /etc/nginx/ssl/d2/certificate.crt;
      ssl_certificate_key /etc/nginx/ssl/d2/private.key;
  
      location / {
  
          try_files $uri $uri/ /index.html;
  
      }
  
  }
  </code></pre>
  
  <p>This doesn't work, it just loads the first cert resulting in invalid cert when accessed using the second domain.</p>
  
  <p>The domain certs can't be combined.
  I can't spin two different instances for nginx as the case needs to help me out with n-Domains pointing to same IP preferably using one nginx server.</p>
  
  <p>Is there a way out?</p>