Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just set up a micro instance of an Ubuntu web server an Amazon EC2. Everthing is running great, I've managed to configure the VirtualHost but I'm having a hard time setting up a subdomain. Here's what I've done:

$ mkdir /var/www/mydomain
$ mkdir /var/www/mysubdomain
$ chmod -R 774 /var/www/mydomain
$ chmod -R 774 /var/www/mysubdomain

$ vim /etc/apache2/sites-available/mydomian

<VirtualHost *:80> 
 DocumentRoot /var/www/mydomian 

$ vim /etc/apache2/site-available/mysubdomain

<VirtualHost *:80> 
 ServerName mysubdomain.localhost # also tried 
 DocumentRoot /var/www/mysubdomian

 <Directory /var/www/mysubdomain/ >
  Options Indexes FollowSymLinks MultiViews +Includes
  AllowOverride All
  Order allow,deny
  allow from all


$ ln -s /etc/apache2/sites-available/mydomian /etc/apache2/sites-enabled/mydomian
$ ln -s /etc/apache2/sites-available/mysubdomain /etc/apache2/sites-enabled/mysubdomain

After restarting Apache works fine but doesn't work. Any ideas?

PS I've also added staging.localhost to /etc/hosts (not sure if I need to do that but...)

share|improve this question
I am little confused here. Your DocumentRoot is at /var/www/mysubdomain, but your directory directive is at is at /var/www/staging. Do you mean Directory to be /var/www/mydomain? – Rilindo Oct 3 '11 at 0:21
@Rilindo yes you're right – jwerre Oct 3 '11 at 3:33

remove any symlinks in /etc/apache2/sites-enabled and then

sudo a2ensite mydomain
sudo a2ensite mysubdomain
sudo apache2ctl restart

Also, make sure your NameVirtualHost directive comes before the VirtualHost configs are read. An easy way to do this is to add it to /etc/apache2/ports.conf

You probably have a default conf in sites-available (probably symlinked as 000-default in sites-enabled). If you want to keep that default config, you can add NameVirtualHost line at the beginning of that file.

share|improve this answer
I removed the 000-default from sites-enabled. Should I re-add it? – jwerre Oct 3 '11 at 0:48
Also, do you think it's better to use myIpAddress:80 or *:80 for the NameVirtualHost value? – jwerre Oct 3 '11 at 0:50
sites-enabled/000-default -> sites-available/default is used for requests that don't match a ServerName or ServerAlias directive. It's probably a good idea to have a config for that, so if in doubt, keep it. – xofer Oct 3 '11 at 6:00
Unless you have a reason to specify the IP address (like for hosting sites on a different IPs) you might as well use *:80 – xofer Oct 3 '11 at 6:02

chances are your NameVirtualHost is wrong.. it should match what is in your virtualhost section so it should be

NameVirtualHost *:80

Also not sure what this is

$ ln -s /etc/apache2/sites-available/mydomian $ vim /etc/apache2/sites-enabled/mydomian

I'm guessing a typo? but are they in sites-enabled ok?

share|improve this answer
A added NameVirtualHost and no change. I get this warning when i restart Apache: [warn] NameVirtualHost *:80 has no VirtualHosts – jwerre Oct 2 '11 at 19:07
yes that is a typo – jwerre Oct 2 '11 at 19:42
then they aren't in sites-enabled correctly – Mike Oct 2 '11 at 19:44
up vote 0 down vote accepted

I found the issue, thanks for the help guys. It turns out my apache config files where fine. I needed to create an A (host) record at with my domain registar that pointed to the EC2 "Elastic" IP.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.