Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Virtual Host problem; resolving to same domain

Posted on 2006-10-24
6
Medium Priority
?
373 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month7 days, 6 hours left to enroll

783 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