Link to home
Start Free TrialLog in
Avatar of minnirok
minnirok

asked on

Virtual Host problem; resolving to same domain

Hello!  I'm attempting to setup my webserver to host 3 different websites, each of which have a seperate domain name and share a common IP hosted off of one machine.  I'm new to using Virtual Hosts -- I'm having an issue where *all* domains are resolving to the first domain rather than to the intended domain.  

my httpd.conf reads:
------------

Listen 192.168.1.2:80
NameVirtualHost *:80

<VirtualHost 192.168.1.2:80>
  ServerName  www.domainone.com
  DocumentRoot  /var/www/html/done
</VirtualHost>

<VirtualHost 192.168.1.2:80>
  ServerName  www.domaintwo.com
  DocumentRoot /var/www/html/dtwo
</VirtualHost>

<VirtualHost 192.168.1.2:80>
  ServerName  www.domainthree.com
  DocumentRoot /var/www/html/dthree
</VirtualHost>

-----------------

I would be grateful if you can shed some light on what I'm missing or doing wrong!  Thnx!
Avatar of minnirok
minnirok

ASKER

I.E. the problem is that accessing www.domaintwo.com or www.domainthree.com is bringing up the files for domainone.com which are stored localy in /var/www/html/done
Looks fine for me, but my config have something reverted comparing to Yours, try it...

Listen 80
NameVirtualHost 192.168.1.2:80
Avatar of periwinkle
I agree with ravenpl - I'd specify the IP address in the NameVirtualHost command if it isn't working.  

The Apache web server will deliver the first entry as a 'default' if nothing matches.

Is it possible that your domaintwo.com or domainthree.com actually point to a different IP address which points to the same server?
Thanks guys. It looks like the problem occurs if I have the NameVirtualHost set to *:80

With the *:80 setting, all my traffic gets routed through to domainone.com...  I don't yet understand why this occurs.  Setting the virtual host to *all* IP addresses on port 80 (ie *:80) really shouldn't be messing up the individual virtualhosts -- since each virtualhost is set to 192.168.1.2:80 they should still be able to resolve to the proper domain.  But, yeah, somehow under this setting the first domain supercedes all others...  Am I missing something?

Also, possibly relevant, ServerName is set to 192.168.1.2:80

Thanks ravenpl, changing my settings to listen only based on port and namevirtualhost to a specific IP does resolve the problem.  In the interest of learning, I'm very curious to learn why the initial settings don't work!  Any theories?
ASKER CERTIFIED SOLUTION
Avatar of ravenpl
ravenpl
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great!  I had missed that note about how the virtualhost and namevirtual host have to match :)

Thanks, ravenpl!