When running SSL on more than one virtual host (one IP), I get a weird issue when virtual hosts are defined in different orders. One virtual host is a TLD (<a href="http://example.com">example.com</a>), and one is an alias I set in /etc/hosts (alias). Both use their own certificates and work fine when I define them in this order:<br>
<br>include /etc/nginx/vhosts/ssl_example.com.conf;<br>include /etc/nginx/vhosts/ssl_alias.conf;<br><br>But when I reverse the order, both hosts try to use (alias)&#39;s certificate, so I get an ssl warning when trying to connect to (<a href="http://example.com">example.com</a>). <br>
<br>In both cases, I use &quot;listen 443&quot; and server_name is set as (<a href="http://example.com">example.com</a>) and (alias). I don&#39;t listen on 443 except in virtual hosts, all with server_name defined. When I use &quot;listen 443 default ssl&quot; instead of &quot;listen 443&quot; for (<a href="http://example.com">example.com</a>), this problem goes away. It looks like nginx takes the first virtual host that listens on 443 if I try to connect to the server on a host that isn&#39;t listening on 443.<br>
<br>But I still don&#39;t understand.. both of the above are valid hosts, so why does the order in which I include the virtual hosts cause different results?<br>