Apache completely ignores ServerName directive when choosing VirtualHost configured for SSL (port 443)

49 Views Asked by At

I've been working ENTIRE day on this, I even asked ChatGPT and I can't find damn solution. Why is Apache completely ignoring ServerName directive when choosing VirtualHost configured for SSL (port 443). When I go to htps://siteB.com , then it loads SSL certificate of siteA and it just looks bad. It should use the very last VirtualHost with redirection for siteB.com . I tried TENS of different combinations and I'm stuck. It looks like a damn bug. Or am I wrong? Please help.

# ----- test.siteA.com -----
<VirtualHost *:80>
    ServerName test.siteA.com

    DocumentRoot "c:/htdocs"
    <Directory "c:/htdocs">
        Options Indexes FollowSymLinks ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

# ----- test.siteA.com -----
<VirtualHost *:443>
    ServerName test.siteA.com

    DocumentRoot "c:/htdocs"
    <Directory "c:/htdocs">
        Options Indexes FollowSymLinks ExecCGI
        AllowOverride All
        Require all granted
    </Directory>

    SSLEngine on
    SSLCertificateFile "c:/Apache24/Certs/siteA.com.crt.pem"
    SSLCertificateKeyFile "c:/Apache24/Certs/siteA.com.key.pem"
    SSLCertificateChainFile "c:/Apache24/Certs/siteA.com.ca.pem"
</VirtualHost>

# ----- siteB.com -----
<VirtualHost *:80>
    ServerName siteB.com

    DocumentRoot "C:\htdocs2"
    <Directory "C:\htdocs2">
        Options Indexes FollowSymLinks ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

# ----- siteB.com -----
<VirtualHost *:443>

    ServerName siteB.com
    
    Redirect permanent / http://siteB.com
    
</VirtualHost>
0

There are 0 best solutions below