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'm running an AWS setup that currently consists of an ELB pointing to a single EC2 instance. The instance is running Ubuntu 12.04.2 and Apache 2.22.2. I've setup several subdomains on the server in the past. I'm trying to set another one up today, but I'm beating my head against the wall trying to figure out what I missed. I'm sure it's some little step that I've overlooked or gotten not-quite-right.

My DNS records are setup using Route 53. I logged in to the AWS console and added a new CNAME record for my server. We'll call it samael.example.com. It looks like this:

samael.example.com. 3600    IN  CNAME   web-pool-xxxxxxxxxx.us-east-1.elb.amazonaws.com.

That seems to be working just fine, as pointing my browser to sameael.example.com brings up the default VirtualHost.

So, all I have left to do now is create another VirtualHost config file, right?

mkdir /http/www/samael.example.com
touch /httpd/www/samael.example.com/index.html
cd /etc/apache2/sites-available
sudo cp dav.example.com samael.example.com
sudo sed -i 's/dav.example.com/samael.example.com/g' samael.example.com
cd ../sites-enabled
sudo ln -s ../sites-available/samael.example.com
sudo apachectl restart

That should be it, right? But when I point my browser to samael.example.com, it's still pointing to the default VirtualHost. What step am I skipping?

cat samael.example.com

<VirtualHost *:80>
    ServerName samael.example.com
    ServerAdmin webmaster@localhost

    DocumentRoot /httpd/www/samael.example.com
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    <Directory /httpd/www/samael.example.com>
            Options FollowSymLinks
            AllowOverride All
            Order allow,deny
            allow from all

    ErrorLog /var/log/apache2/samael.example.com-error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/samael.example.com-access.log combined


Per the request in the comments:

sudo apache2ctl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server dav.example.com (/etc/apache2/sites-enabled/dav.example.com:1)
         port 80 namevhost dav.example.com (/etc/apache2/sites-enabled/dav.example.com:1)
         port 80 namevhost dev.example.com (/etc/apache2/sites-enabled/dev.example.com:1)
         port 80 namevhost example.com (/etc/apache2/sites-enabled/example.com:1)
         port 80 namevhost new.example.com (/etc/apache2/sites-enabled/new.example.com:1)
         port 80 namevhost samael.example.com (/etc/apache2/sites-enabled/samael.example.com:1)
         port 80 namevhost stage.example.com (/etc/apache2/sites-enabled/stage.example.com:1)
         port 80 namevhost test.example.com (/etc/apache2/sites-enabled/test.example.com:1)
Syntax OK

The output of this is a bit puzzling to me. I would expect the default to be example.com rather than dav.example.com. The configuration file for example.com has ServerAlias * defined in it.

share|improve this question
Check apache2ctl -S, also for ubuntu there are the helpers a2ensite a2dissite tools for managing enabled and available links. manpages.ubuntu.com/manpages/hardy/man8/a2ensite.8.html and manpages.ubuntu.com/manpages/hardy/man8/a2enmod.8.html can somewhat simplify working with Apache2 on Ubuntu. –  David Jun 18 '13 at 20:19
a, b, c, D, and then E. To enforce ordering, prefix with numbers for priority as Apache's include directive works Alphanum sort ordered in a EXT based filesystem. ( Apache, not ubuntu re: include directive ) –  David Jun 18 '13 at 20:36

1 Answer 1

up vote 2 down vote accepted

It's possible that your vhost configuration file is not being seen by apache, either for lack of an include directive, or a lack of permissions.

Ensure that in your main configuration file you have a directive like

Include /etc/apache2/sites-enabled/*

If it is in a conditional block, such as <IfDefine VHOSTS>, ensure the condition is evaluating to true (eg. by ensuring the correct define is specified or the correct module is loaded).

Also, ensure that whichever user apache is running as (usually apache) has permission to read the file and enumerate the sites-enabled directory. Specifically, it needs read and execute on the sites-enabled directory, and read on all the configuration files in sites-enabled.

Per your edit, it is probable that the ServerAlias * directive you have is confusing things. This is not the way to designate a default vhost. The default vhost, with name-based virtual hosting, is used only when no other virtual host matches (ServerAlias or ServerName), and is simply the first one that is loaded, in alphabetical order. This is how the dav.example.com host was most likely chosen. To overcome this, usually the intended virtual host configuration file is named something like 00_default_vhost.conf.

Matching is also done in the order files are read. So, any sites that aren't dav.example.com or dev.example.com will be matched by example.com with the wildcard alias.

share|improve this answer
On the last line of my apache2.conf file, I have Include sites-enabled/. It is not in a conditional block. All of the other subdomains are working fine. Apache is running as www-data and has read access to all of the configuration files and site directories. –  Ben Harold Jun 18 '13 at 20:32
What is the correct way to designate a default host? –  Ben Harold Jun 18 '13 at 20:33
I'll edit again and explain. –  Falcon Momot Jun 18 '13 at 20:36
The first defined Virtual Host will be the default. Since you're using include, I believe that will be based on the alphabetical filename. Hence dav.example.com beating out example.com. –  Christopher Karel Jun 18 '13 at 20:38
@BenHarold serverfault.com/a/373673/30247 plus my comment will get you on track with specifying which is the default –  David Jun 18 '13 at 20:39

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.