NL3294 NL3294 - 3 months ago 14
Apache Configuration Question

Virtual host files won't direct correctly

I have 4 virtual hosts.

I'm using Zend server. The httpd.conf file seems to include the virtual host conf files using a wildcard like so:

Include "C:\blah\blah2\Zend\ZendServer/etc/sites.d/vhost_*.conf"


My virtual host conf files are below. Now, what's puzzling to me is that
when I go to https://www-test.blah.com, or https://www-test2.blah.com, it works fine. But when I go to https://review-test.blah.com, it goes to the www-test.blah.com

This baffles me, because as far as I can tell, everything looks like it's set up the same way.

Is it possible that since the virtual host files are being included via wildcard, does the order in which they get included matter? If it's alphabetical order, then it would be included in the order shown.

One thing I did notice is that if I'm on the server, https://review-test.blah.com works fine. But when I'm somewhere else my the network, it directs me to https://www-test2.blah.com.

Or is there something else that can affect how Apache chooses the virtual host? For example, does the certificate file matter?

Listen 80
Listen 443
<VirtualHost *:80>
ServerName portal.blah.com:80

</VirtualHost>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

NameVirtualHost review-test.blah.com:443

<VirtualHost review-test.blah.com:443>
OTHER STUFF HERE
OTHER STUFF HERE
OTHER STUFF HERE
OTHER STUFF HERE

SSLEngine on

SSLCertificateFile "C:\blah\blah\Apache2\conf\extra\ssl\review-test.blah.com.crt"
SSLCertificateKeyFile "C:\blah\blah\Apache2\conf\extra\ssl\review-test.blah.com.key"

ServerName review-test.blah.com
ServerAlias review-test.blah.com

</VirtualHost>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

NameVirtualHost www-test.blah.com:443

<VirtualHost www-test.blah.com:443>
OTHER STUFF HERE
OTHER STUFF HERE
OTHER STUFF HERE
OTHER STUFF HERE

SSLEngine on
SSLCertificateFile "C:\blah\blah\Apache2\conf\extra\ssl\star.blah.com.crt"
SSLCertificateKeyFile "C:\blah\blah\Apache2\conf\extra\ssl\star.blah.com.key"


ServerName www-test.blah.com
ServerAlias www-test.blah.com

</VirtualHost>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

NameVirtualHost www-test2.blah.com:443

<VirtualHost www-test2.blah.com:443>
OTHER STUFF HERE
OTHER STUFF HERE
OTHER STUFF HERE
OTHER STUFF HERE

SSLEngine on
SSLCertificateFile "C:\blah\blah\Apache2\conf\extra\ssl\star.blah.com.crt"
SSLCertificateKeyFile "C:\blah\blah\Apache2\conf\extra\ssl\star.blah.com.key"


ServerName www-test2.blah.com
ServerAlias www-test2.blah.com
</VirtualHost>

Answer

I was able to fix it.

The command below was helpful in seeing how the virtualhosts were being parsed.

httpd -S 

My solution is below:

Listen 80
Listen 443
<VirtualHost *:80>
    ServerName portal.blah.com:80

</VirtualHost>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



<VirtualHost *:443>
    OTHER STUFF HERE
    OTHER STUFF HERE
    OTHER STUFF HERE
    OTHER STUFF HERE

    SSLEngine on        

    SSLCertificateFile "C:\blah\blah\Apache2\conf\extra\ssl\review-test.blah.com.crt"
    SSLCertificateKeyFile "C:\blah\blah\Apache2\conf\extra\ssl\review-test.blah.com.key"

    ServerName review-test.blah.com
    ServerAlias review-test.blah.com

</VirtualHost>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

NameVirtualHost *:443

<VirtualHost *:443>
    OTHER STUFF HERE
    OTHER STUFF HERE
    OTHER STUFF HERE
    OTHER STUFF HERE

    SSLEngine on
    SSLCertificateFile "C:\blah\blah\Apache2\conf\extra\ssl\star.blah.com.crt"
    SSLCertificateKeyFile "C:\blah\blah\Apache2\conf\extra\ssl\star.blah.com.key"


    ServerName www-test.blah.com
    ServerAlias www-test.blah.com

</VirtualHost>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

<VirtualHost *:443>
    OTHER STUFF HERE
    OTHER STUFF HERE
    OTHER STUFF HERE
    OTHER STUFF HERE

    SSLEngine on
    SSLCertificateFile "C:\blah\blah\Apache2\conf\extra\ssl\star.blah.com.crt"
    SSLCertificateKeyFile "C:\blah\blah\Apache2\conf\extra\ssl\star.blah.com.key"


    ServerName www-test2.blah.com
    ServerAlias www-test2.blah.com
</VirtualHost>