Friday, August 15, 2014

httpd - Apache name-based vhost (ServerAlias)



I'm currently looking at the apache documentation regarding virtual host. It gives an example on this page: http://httpd.apache.org/docs/2.0/vhosts/name-based.html



The example they show is:





ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain



Wouldn't it work also with this type of config?:





ServerName *.domain.tld
DocumentRoot /www/domain



Or this:




ServerName domain.tld
ServerAlias *.domain.tld

DocumentRoot /www/domain


Answer



You can't use wildcards to specify ServerName as it has to be a FQDN. Your first example with ServerName *.domain.tld will not work as this is not a FQDN. Your second example will work and is quite a common configuration.



One thing to note is that apache processes these directives from top to bottom in the order they are defined and will act upon the first match.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...