?
Solved

Virtual Host problem; resolving to same domain

Posted on 2006-10-24
6
Medium Priority
?
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 400 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

752 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