Why is this setting for Name-based Virtual Host settings not working?

Posted by Kave on Server Fault See other posts from Server Fault or by Kave
Published on 2012-06-10T14:06:33Z Indexed on 2012/06/10 16:41 UTC
Read the original article Hit count: 270

Filed under:

I have two domains (siteA.com & SiteB.com) that point to the same webserver and I would like to show different web pages for each.

The steps I have taken so far are:

Copy the default site (siteA) to siteB

1) sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/siteB 2) sudo vim /etc/apache2/sites-available/siteB

<VirtualHost *:80>
        ServerAdmin [email protected]

        DocumentRoot /var/www/siteB
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/siteB>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride FileInfo Indexes
                Order allow,deny
                allow from all
        </Directory>

</VirtualHost *:80>

Then I created under /var/www/siteB and created a sample index.html in there.

However when I load my domain siteB.com I still get directed to /var/www/siteA. Why is that?

Do I have to rename the /etc/apache2/sites-available/default to /etc/apache2/sites-available/siteA as well?

UPDATE:

Thanks to the answer below it seems I had forgotten next to enabling the site also another entry:

<VirtualHost *:80>
            ServerAdmin [email protected]
            ServerName siteB.com
            ServerAlias www.siteB.com
</VirtualHost *:80>

in order to include all subdomains as well then do:

<VirtualHost *:80>
            ServerAdmin [email protected]
            ServerName siteB.com
            ServerAlias *.siteB.com
</VirtualHost *:80>

Same goes for siteA.

© Server Fault or respective owner

Related posts about apache2