Hi,
I am configuring my staging server apache with virtual host.
Whenever i try to access the site with host entry in my system(hosts file)
it's always displaying first site in vhost. i am not able to access other sites.
always i am getting www.ocms.com site , i am not able to access www.uscms.com site

my httpd.conf details are below

NameVirtualHost *.80
<VirtualHost *:80>
   DirectoryIndex index.php
	DocumentRoot /cmsdata/cms/sites/home
	ServerName www.ocms.com
    ErrorLog /usr/local/apache/logs/o-error_log
	CustomLog /usr/local/apache/logs/o-access_log combined
</VirtualHost>

<VirtualHost *:80>
    DirectoryIndex index.php
	DocumentRoot /cmsdata/cms/sites/us
	ServerName www.uscms.com
    ErrorLog /usr/local/apache/logs/ous-error_log
	CustomLog /usr/local/apache/logs/ous-access_log combined
</VirtualHost>

Look at your apache httpd.conf if the line that includes your vhosts file isn't commented.

Try to use:

NameVirtualHost *
<VirtualHost *>
	DocumentRoot /cmsdata/cms/sites/home
	ServerName www.ocms.com
	ErrorLog /usr/local/apache/logs/o-error_log
	CustomLog /usr/local/apache/logs/o-access_log combined
</VirtualHost>

<VirtualHost *>
	DocumentRoot /cmsdata/cms/sites/us
	ServerName www.uscms.com
	ErrorLog /usr/local/apache/logs/ous-error_log
	CustomLog /usr/local/apache/logs/ous-access_log combined
</VirtualHost>

also add in your /etc/hosts:

127.0.0.1    www.ocms.com
127.0.0.1    www.uscms.com

With these settings should be ok, at least working from the same machine.

Haii am new to this forum.
i also have this issue and i solved by giving ip instead of '*' in both vitualhosts
and in Namedvirtualhost entry
eg:<VirtualHost 127.0.0.1:80>
also add ip in etc/hosts

Hi,
Look at your httpd.conf file and search for Listen directive
if its commanted please uncomment it
#Listen 80
to
Listen 80

don't forget to restart your apache service

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.