Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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> 
 ServerAdmin me@me.com 
 ServerName mydomain.com 
 ServerAlias www.mydomain.com 
 DocumentRoot /var/www/mydomian 
</VirtualHost> 

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

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

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

</VirtualHost> 

$ 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 mydomain.com works fine but mysubdomain.mydomain.com 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

3 Answers 3

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

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

Your Answer

 
discard

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.