0

i know its possible to use wildcard on apache ServerAlias. I'm trying to configure 3 sets but the configuration is falling back on one vhosts instead of each separate.

dev environment

ServerName dev.somedomain.com
ServerAlias dev.*.somedomain.com
docroot /var/www/dev.somedomain.com

release environment

ServerName release.somedomain.com
ServerAlias release.*.somedomain.com
docroot /var/www/release.somedomain.com

production environment

ServerName somedomain.com
ServerAlias www.somedomain.com *.somedomain.com www.*.somedomain.com
docroot /var/www/somedomain.com

But when i browse to dev.test.somedomain.com i get the contents of somedomain.com (not dev.somedomain.com). What am i missing here ?

5
  • Make sure that the production VHosts get loaded last. Apr 21, 2016 at 13:55
  • And if that is not possible (im using directadmin) ? Apr 21, 2016 at 13:58
  • That is how Apache works, it uses the first VHost that matches the Wildcard. If production is first, it will always be matched. No other way as far as I can tell. Apr 21, 2016 at 15:02
  • First of all, thanks, Is there a way to make a wildcard that matches abc.somedomain.com and not def.abc.somedomain,com e.g. a wildcard that only matches 1 dot (.) ? Apr 22, 2016 at 6:22
  • Nope. Apache ServerName and ServerAlias do not support regex or other complex matching. Although I will post a solution for you in a sec. Apr 22, 2016 at 8:23

1 Answer 1

0

As I also said in my comments, you can fix this by changing the order of the VirtualHosts in the Apache configuration. Since this is not possible, I will point you to 3 alternatives:

  1. Use mod_vhost_alias. This might also not be an option, but still.

  2. Use separate IP addresses for Production/Development/Release. This should be relatively easy if you are on an internal network/behind a NAT.

  3. Use separate ports in Apache for each VHost and put a HAProxy instance on the same server that redirects to the correct port. In HAProxy you can do regex matching on the Host header much better.

1
  • Although not i was hoping I came to the same solution. Apr 26, 2016 at 6:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .