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 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 info@siteB.com

        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 info@siteB.com
            ServerName siteB.com
            ServerAlias www.siteB.com
</VirtualHost *:80>

in order to include all subdomains as well then do:

<VirtualHost *:80>
            ServerAdmin info@siteB.com
            ServerName siteB.com
            ServerAlias *.siteB.com
</VirtualHost *:80>

Same goes for siteA.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Did you enable siteB by using command a2ensite siteB and then restart the webserver?

share|improve this answer
    
Oh right. I missed that thank alot. I also added to each site ServerName siteA.com ServerAlias www.siteA.com and same for siteb. Is that mandatory to do? –  Kave Jun 10 '12 at 14:25
    
I prefer to go for *.siteA.com which means all subdomains of siteA.com. –  Hex Jun 10 '12 at 14:26
    
I see, its a bit hard to follow this up in comments. I have updated the question. Have I understood you correctly? –  Kave Jun 10 '12 at 14:34
1  
Yes, "ServerAlias *.siteB.com" is exactly how I like it to be :) –  Hex Jun 10 '12 at 14:36
    
You should vote my answer not my comment :P –  Hex Jun 10 '12 at 14:40
add comment

I have been struggling for days with a virtualhost problem... Maybe related: Here is what I had:

<VirtualHost *:80>
     ServerName www.domain1.com
     ServerAlias domain1.com
     Include /etc/apache2/vhosts.d/domain1.include

     <IfModule mpm_peruser_module>
            ServerEnvironment apache apache
     </IfModule>
</VirtualHost>

<VirtualHost domain2:80>
    ServerAlias domain2.com
    ServerName www.domain2.com
    Include /etc/apache2/vhosts.d/domain2.include

    <IfModule mpm_peruser_module>
            ServerEnvironment apache apache
    </IfModule>
</VirtualHost>

domain1 was sending out domain2s content!

Finally I changed

<VirtualHost domain2:80>

to

<VirtualHost *:80>

and it worked.

  • "IP" based virtualhost setting was running on domain2, which has the same IP as domain1, and was never even looking at my first VirtualHost entry

  • The tags need to be identical IP [and port] for it to look at ServerName and ServerAlias

Hope this helps someone.

share|improve this answer
add comment

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.