I have 2 sites defined in a file called virtualhosts.conf, loaded at the end of httpd.conf.
They both have the format of:
<VirtualHost IP:80>
DocumentRoot D:/Site/A/
...
</VirtualHost>
<VirtualHost IP:443>
DocumentRoot D:/Site/A/
...
</VirtualHost>
<VirtualHost IP__2:80>
DocumentRoot D:/Site/B/
...
</VirtualHost>
<VirtualHost IP__2:443>
DocumentRoot D:/Site/B/
...
</VirtualHost>
If I load https://sitea.com, with the above config, it loads just fine. If I load https://siteb.com with the above config though, it breaks, saying that siteb is identifying itself as sitea. If I flip the order of the entries:
<VirtualHost IP__2:80>
DocumentRoot D:/Site/B/
...
</VirtualHost>
<VirtualHost IP__2:443>
DocumentRoot D:/Site/B/
...
</VirtualHost>
<VirtualHost IP:80>
DocumentRoot D:/Site/A/
...
</VirtualHost>
<VirtualHost IP:443>
DocumentRoot D:/Site/A/
...
</VirtualHost>
Now, siteb loads just fine, but sitea throws an error that it is identifying itself as siteb.
What is going on? It seems like Apache is defaulting to the ‘top’ entry in the file, even though both seem to be valid, for their domains, if they are first.
EDIT: The top of my httpd.conf:
Listen 80
Listen 443
NameVirtualHost IP.50:80
NameVirtualHost IP.50:443
NameVirtualHost IP.51:80
NameVirtualHost IP.51:443
NameVirtualHost IP.52:80
NameVirtualHost IP.52:443
NameVirtualHost IP.53:80
NameVirtualHost IP.53:443
NameVirtualHost IP.54:80
NameVirtualHost IP.54:443
NameVirtualHost IP.55:80
NameVirtualHost IP.55:443
NameVirtualHost IP.56:80
NameVirtualHost IP.56:443
SSL is established ahead of HTTP request and the server doesn’t know whose certificate to present when it receives the request. This problem doesn’t have general solution other than have a dedicated IP for each secure domain. And BTW your question is off-topic on StackOverflow.