jQuery in Action, 2nd edition*
The moose likes Tomcat and the fly likes Apache virtual hosting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Apache virtual hosting" Watch "Apache virtual hosting" New topic
Author

Apache virtual hosting

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi there,
I have an Apache 2.0 running on localhost.
My default DocumentRoot is set to:
DocumentRoot "H:/apache2.0/Apache2/htdocs"

I'm trying to use virtual hosting (for testing), and I've got the following settings:
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1>
DocumentRoot "c:/mywebpage"
ServerName localhost
</VirtualHost>
Now when I type "http://localhost" in my browser, apache still serves the index page from the default DocumentRoot !
Why's this ?

Thanks everyone
Dennis
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

Because you have a conflict between the virtual host and the default host - you're giving them both the same URL!
A more realistic setup would be to do:
<VirtualHost 127.0.0.1:8080>
in order to see the alternate (virtual) host as http://localhost:8080.
This requires that you tell Apache it's OK to serve out of port 8080 in addition to port 80.
The other use of VirtualHost is to access under a different domain, like so:
<VirtualHost www.mydomain.com>
<VirtualHost info.mydomain.com>
<VirtualHost www.otherdomain.net>
Which provides 4 total host URLs - the default +
http://www.mydomain.com, http://info.mydomain.com, and http://www.otherdomain.net.


Customer surveys are for companies who didn't pay proper attention to begin with.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
cool .. thanks a lot !
 
jQuery in Action, 2nd edition
 
subject: Apache virtual hosting