Solved

Virtual Host problem; resolving to same domain

Posted on 2006-10-24
6
355 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

14 Experts available now in Live!

Get 1:1 Help Now