Solved

Virtual Host problem; resolving to same domain

Posted on 2006-10-24
6
353 Views
Last Modified: 2010-03-04
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!
0
Comment
Question by:minnirok
  • 3
  • 2
6 Comments
 
LVL 7

Author Comment

by:minnirok
ID: 17801019
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
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17801476
Looks fine for me, but my config have something reverted comparing to Yours, try it...

Listen 80
NameVirtualHost 192.168.1.2:80
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 17803696
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?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 7

Author Comment

by:minnirok
ID: 17805657
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?
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 100 total points
ID: 17805817
In fact http://httpd.apache.org/docs/2.0/mod/core.html#namevirtualhost says
Note that the argument to the <VirtualHost> directive must exactly match the argument to the NameVirtualHost directive.
So I suppose the following could work
NameVirtualHost *:80
<VirtualHost *:80> //not the IP!, OR
<VirtualHost _default_:80>

But then, the same link says to not use it this way
Note, that the "main server" and any _default_ servers will never be served for a request to a NameVirtualHost IP address (unless for some reason you specify NameVirtualHost but then don't define any VirtualHosts for that address).

0
 
LVL 7

Author Comment

by:minnirok
ID: 17805907
Great!  I had missed that note about how the virtualhost and namevirtual host have to match :)

Thanks, ravenpl!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now