Monday, August 25, 2014

apache 2.2 - Difference between ServerName and ServerAlias





I'm not quite clear on the difference between ServerName and ServerAlias. It looks like both of them work as host name settings, except that ServerAlias only works within the tag.



That is, I can do:



ServerName www.domain1.com
ServerName www.domain2.com


or:





ServerName www.domain1.com
ServerName www.domain2.com



and both domains work on the same box. Can I use either ServerName or ServerAlias in this case?


Answer



The ServerName directive is





Hostname and port that the server uses to identify itself




Whilst ServerAlias is




Alternate names for a host used when matching requests to name-virtual hosts





Given a vhost configured like



 ...
ServerName example.com
ServerAlias www.example.com foo.example.com *.somewherelse.org
...


apache would respond to example.com, www.example.com foo.example.com and anything in .somewherelse.org with this VirtualHost


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...