Wednesday, September 30, 2015

virtualhost - Apache Virtual Host Not Matching ServerAlias



I have a VirtualHost block defined like this for a domain:




ServerName example.com:443
ServerAlias www.example.com:443



If I use this URL, https://example.com/, the site loads as expected. When I use this URL, https://www.example.com/, Apache is delivering the content and SSL certificate for the very first virtual host defined in my config.



I understand the definition order of virtual hosts is significant, so it seems to me that the ServerAlias directive is not being matched for some reason. My web searches haven't turned up a clue for how to fix this issue.


Answer



Because you didn't care to read documentation on the ServerAlias Directive and therefore you have a wrong syntax.



ServerAlias hostname [hostname] ...


That's different from ServerName that can have optional port and scheme, but only one hostname:




ServerName [scheme://]fully-qualified-domain-name[:port]

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