Saturday, August 15, 2015

Apache issue with VirtualHosts

I am setting up a small website in-place on the production server. While we are finalizing all the settings for the final domain we've located it on dev.domain.com, so that our visitors don't see a potentially buggy site as they go to www.domain.com or domain.com. I did this by specifying a virtualhost catching dev.domain.com with the documentroot of the "real" site, and creating a new site with the virtualhost catching www.domain.com and domain.com, with the documentroot pointing to a directory parallell to the "real" site, containing nothing but a index.html. This site would show the visitor a message about the site reconstruction.



These are the site config files:



# dev.domain.com

ServerAdmin admin@domain.com
ServerName dev.domain.com


DirectoryIndex index.html
DocumentRoot /var/www/www.domain.com/htdocs/

ScriptAlias /cgi-bin/ /var/www/www.domain.com/cgi-bin/

Options +ExecCGI


ErrorLog /var/log/apache2/www.domain.com/error.log

CustomLog /var/log/apache2/www.domain.com/access.log combined



# a-notice-site

ServerAdmin admin@domain.com
ServerName www.domain.com
ServerAlias domain.com


DirectoryIndex index.html
DocumentRoot /var/www/notice-site/htdocs/

ScriptAlias /cgi-bin/ /var/www/www.domain.com/cgi-bin/

Options +ExecCGI


ErrorLog /var/log/apache2/www.domain.com/error.log
CustomLog /var/log/apache2/www.domain.com/access.log combined




So, my problem is this: When typing www.domain.com, www.domain.com. and even domain.com., i reach the notice site just fine, but when accessing just domain.com (without the trailing dot) my browser address bar tells me i've been routed to www.domain.com/notice-site/htdocs and i get a 404 that the url was not found. Accessing the dev site works perfectly.



I have a small hunch that this has something to do with the way i've set up the virtual hosts, but sadly i can't figure out why it would cause this effect. Has anyone heard of something similar or what could cause it?



apache2ctl -S gives:



VirtualHost configuration:

wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server www.domain.com (/etc/apache2/sites-enabled/a-notice-site:4)
port 80 namevhost www.domain.com (/etc/apache2/sites-enabled/a-notice-site:4)
port 80 namevhost dev.domain.com (/etc/apache2/sites-enabled/dev.domain.com:4)
Syntax OK

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