1

I've got a httpd24 server that I want to use to server multiple domains.

I've got a 3 VirtualHost definitions.

<VirtualHost *:443>
   ServerName one.example.com
   # SSL stuff
   DocumentRoot "/opt/rh/httpd24/root/var/www/one
</VirtualHost>

<VirtualHost *:443>
   ServerName two.example.com
   # SSL stuff
   DocumentRoot "/opt/rh/httpd24/root/var/www/two
</VirtualHost>

<VirtualHost _default_:443>
   Redirect / https://two.example.com
</VirtualHost>

The idea being that if the exact url one.example.com or two.example.com is entered they'll get the appropriate pages. If any other domain is received I want to redirect to the https://two.example.com url.

However I'm finding that if I enter https://three.example.com I'm not getting redirected, instead the content for one.example.com is served.

Note that https://two.example.com does work as expected. My issue is that I'm expected unknown domains to be redirected, but they are instead being resolved as if they were one.example.com.

The RPM I installed originally was httpd24-httpd-2.4.27-8.el6.1.x86_64.

Any ideas what is going on?

0
1

The first virtual host entry typically becomes the default virtual host that will be used to handle requests that aren't matched by the subsequent virtual host entries
(simplified ; https://httpd.apache.org/docs/2.4/vhosts/details.html provides a much more in-depth explanation...)

The string _default_ in a VirtualHost entry, is just an alias for *, in practice it usually does not actually make a particular VirtualHost entry the default VirtualHost when it is not the first definition...

Change the order of your virtual host definitions and your problem should be resolved.

<VirtualHost _default_:443>
   Redirect / https://two.example.com
   # ServerName not needed
   # Any vhost that includes the magic _default_ wildcard is given the same ServerName as the main server. 
   # SSL stuff
</VirtualHost>

<VirtualHost *:443>
   ServerName one.example.com
   # SSL stuff
   DocumentRoot "/opt/rh/httpd24/root/var/www/one
</VirtualHost>

<VirtualHost *:443>
   ServerName two.example.com
   # SSL stuff
   DocumentRoot "/opt/rh/httpd24/root/var/www/two
</VirtualHost>

Not the answer you're looking for? Browse other questions tagged or ask your own question.