title: NGINX Mulitple SSL certificates with one ip, different roots and domains
body: <p>I'm trying to configure nginx with two domains, each with a different ssl certificate and a different root location. 
  The following code shows two times the exact same thing. 
  domain1.com should go to /home/ubuntu/web/html/domain1 and should use  this: /etc/letsencrypt/live/domain1.com/fullchain.pem certificate. domain2.com should go to /home/ubuntu/web/html/domain2 and use this  /etc/letsencrypt/live/domain2.com/fullchain.pem certificate.</p>
  
  <p>I tried the following:</p>
  
  <pre><code>server {  
      listen 80;
      server_name  www.domain1.com;
      return       301 https://domain1.com$request_uri;
  }
  
  server {
      listen 80;
      server_name  domain1.com;
      return       301 https://domain1.com$request_uri;
  }
  
  server {
      listen 443;
      ssl on;
      ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem;
  
      ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
  
      root /home/ubuntu/web/html/domain1;
      index index.php index.html index.htm;
  
      server_name domain1.com, www.domain1.com;
  
      location / {
          try_files $uri $uri/ $uri.html $uri.php?$query_string;
      }
  
  
      error_page 404 /404.html;
  
      error_page 500 502 503 504 /50x.html;
      location = /50x.html {
          root /usr/share/nginx/html;
      }
  
      location ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;
          fastcgi_param MAGE_MODE "developer";
      }
  
  }
  
  
  server {  
      listen 80;
      server_name  www.domain2.com;
      return       301 https://domain2.com$request_uri;
  }
  
  server {
      listen 80;
      server_name  domain2.com;
      return       301 https://domain2.com$request_uri;
  }
  
  server {
      listen 443;
      ssl on;
      ssl_certificate /etc/letsencrypt/live/domain2.com/fullchain.pem;
      ssl_certificate_key /etc/letsencrypt/live/domain2.com/privkey.pem;
  
      ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
  
      root /home/ubuntu/web/html/domain2;
      index index.php index.html index.htm;
  
      server_name domain2.com, www.domain2.com;
  
      location / {
          try_files $uri $uri/ $uri.html $uri.php?$query_string;
      }
  
  
      error_page 404 /404.html;
  
      error_page 500 502 503 504 /50x.html;
      location = /50x.html {
          root /usr/share/nginx/html;
      }
  
      location ~ \.php$ {
          try_files $uri =404;
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;
          fastcgi_param MAGE_MODE "developer";
      }
  
  }
  
  </code></pre>
  
  <p>It turns out that always one server block is chosen as default and also used for the the other domain.</p>
  
  <p>Also adding an extra default server doesn't work.</p>