views:

406

answers:

3

Hello all,

I have setup up 2 virtual hosts that share the same IP on a centos server running apache 2.

#<VirtualHost *:80>
#    ServerAdmin [email protected]
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/a
    ServerName www.a.com
    ServerAlias a.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/b
    ServerName www.b.com
    ServerAlias b.com
</VirtualHost>

Regardless of what URL I point to. Site A shows up.

How can I fix? I should have a.com going to a and b.com going to b.

Thanks all

+6  A: 

Is the following set in your httpd.conf?

NameVirtualHost *

An example from the documentation:

NameVirtualHost *

<VirtualHost *>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
Sebastian Celis
Thank you. You literally saved my life and 1000 people that would have visited a different site!! :)
Abs
+2  A: 

make sure you have this directive as well

NameVirtualHost *

it could be displaying site A because it's set as the default document root. check your global settings, make sure the document root is not set to the same root as site A.

Roy Rico
+2  A: 

I have always declared the domain as the name.. never had issue.

NameVirtualHost localhost:80

<VirtualHost localhost:80>
DocumentRoot "/home/eddie/workspace/"
</VirtualHost>

<VirtualHost digbiz.localhost:80>
DocumentRoot "/home/eddie/workspace/Digital_Business/app/webroot"
</VirtualHost>

<VirtualHost wishlist.localhost:80>
DocumentRoot "/home/eddie/workspace/WishList/app/webroot"
</VirtualHost>

<VirtualHost phpmyadmin.localhost:80>
DocumentRoot "/srv/www/phpMyAdmin"
</VirtualHost>


<VirtualHost test.localhost:80>
DocumentRoot "/home/eddie/workspace/CakePHPTesting/app/webroot"
</VirtualHost>

<VirtualHost auth.localhost:80>
DocumentRoot "/home/eddie/workspace/EntMeetCapt/app/webroot"
</VirtualHost>
Eddie