What virtual host definitions do I need to support subdomain.mydomain.com and * .mydomain.com on the same IP on Apache 2?

I have a virtual host setup on Apache 2 like this (simplified):

<VirtualHost *>
  ServerName domain.com
  ServerAlias *.domain.com
  DocumentRoot /var/www/domain.com/html
</VirtualHost>

<VirtualHost sub1.domain.com>
  ServerName sub1.domain.com
  DocumentRoot /var/www/sub1.domain.com/html
</VirtualHost>

<VirtualHost sub2.domain.com>
  ServerName sub2.domain.com
  DocumentRoot /var/www/sub2.domain.com/html
</VirtualHost>

      

The result I'm looking for is anything that is not sub2.domain.com or sub1.domain.com to go to domain.com. They all need to be on the same default port, and they all have the same IP address.

What actually happens is that sub2 goes to sub2 as expected, and everything else goes to sub1, meaning the wildcard definition is ignored.

How can I fix this?

Thank!

0


source to share


1 answer


Change <VirtualHost sub1.domain.com> to <VirtualHost *> and <VirtualHost sub2.domain.com> to <VirtualHost *> as well. First, it is the default first.



0


source







All Articles