Saturday, March 25, 2017

configuration - VirtualHosts with Apache not respecting ServerName



This has always bugged me and I've never got around to figuring out why Apache does this, I always resorted to the mod_vhost plugin to work around the issue.



Basically, I have 2 vhosts in sites-enabled (Ubuntu server), their contents:





DocumentRoot "/var/www/vhosta.domain.com/"
ServerName vhosta.domain.com

allow from all
Options +Indexes





And




DocumentRoot "/var/www/vhostb.domain.com/"
ServerName vhostb.domain.com

allow from all
Options +Indexes





Now logically these 2 would be accessible separately, however it seems that all requests to my server, no matter what vhosts I define on top of this, are going to vhosta.domain.com.



Am I missing something incredibly obvious? I really don't get why it's doing this..



Thanks


Answer



You are missing a NameVirtualhost; however:





  • DO NOT use VirtualHost *; use VirtualHost *:80 instead.



The following is the correct way:



NameVirtualHost *:80



Servername vhosta



Servername vhostb


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