File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Apache virtual hosting" Watch "Apache virtual hosting" New topic

Apache virtual hosting

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:
DocumentRoot "c:/mywebpage"
ServerName localhost
Now when I type "http://localhost" in my browser, apache still serves the index page from the default DocumentRoot !
Why's this ?

Thanks everyone
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

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:
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:
Which provides 4 total host URLs - the default +,, and

An IDE is no substitute for an Intelligent Developer.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
cool .. thanks a lot !
I agree. Here's the link:
subject: Apache virtual hosting
It's not a secret anymore!