Virtual Hosting


Best Practice for creating a tomcat 5.0 virtual host


It is more efficient to directly edit the server.xml than using the Tomcat Administration tool. Open the server.xml, add a host stanza, Save and restart tomcat.


  • Remote into the host (as you'll need to restart tomcat)
  • Navigate to the wwwroot where the virtual host folders live. (We're using E:/Inetpub/wwwroot) If there isn't one already, create a folder structure outside of the tomcat installation similar to above (see notes for more on this)
  • Create a new folder that matches the fully qualified host name. ( such as E:/Inetpub/wwwroot/
  • Navigate to the tomcat config folder, (on our systems, E:/Program Files/Apache Software Foundation/Tomcat 5.0/conf)
  • Edit the server.xml, copying or adding a new host entry. A host entry looks something like this:
   suffix=".txt" prefix="1098t_log." timestamp="true"/>
  • If there is already a host entry, copy and paste it, then edit the paramters.
    • appBase must to point to the folder you created earler
    • name must match the fully qualified DNS name.
    • prefix can be anything you'll mentally associate with the new host
  • If the new hostname is not yet in DNS, edit the etc/hosts file, adding the new entry. (This is in C:/WINDOWS/system32/drivers/etc/hosts on windows.) An entry in the hosts file should look something like this:
  • Save the file and restart tomcat
You are now ready to install an application under this virtual host.

Steps to add the manager app

You often want to have the manager application available. Since it's stateless you can simply copy the application's xml
  • Navigate to the conf/Catalina folder
  • create a new folder named for the host, such as
  • copy the manager.xml file from conf/Catalina/localhost to here
  • restart tomcat


This entry has been deprecated by the new VHost model in use with Tomcat 5.5 link-here

Why not use the tomcat webapps folder? In general, we want to keep our stuff seperate from tomcat's stuff, that way we can upgrade, delete, whatever, to tomcat without blowing away our webapps.

Why use virtual hosts? This allows us to move the application from server to server, transparently to the client. If we use virtual hosts (and corresponding DNS aliases), we can simply update the DNS entry, run the app in two places while the entry exires from client caches, then be fully transitioned to the new server without anyone needing to change links or bookmarks. To quote Ron Popeil of Ronco fame, "It's Just That Easy".

Can I use the tomcat manager You sure can. It's not always needed as we find autodeploy to work just fine, but if you are updating a single app a lot, it does come in handy. A rough desciption of the procedure is: Go the the tomcat conf/catalina/localhost folder and copy the manager.xml to the tomcat conf/catalina/your_new_host folder. Edit the manager.xml so the app base points to the right spot (factory path is relative, and you'll need to change that to the full path because the new host is not within the tomcat home)

Why use a ROOT context? This isn't really part of creating a virtual host, and It's not critical as we can still use virtual hosts and standard servlet contexts, but it's somewhat prettier to just put in the machine name and let the server tack on the default context (/), rather than the machine name and a context name. (i.e. >> as opposed to >> The latter is simplier and has all the bennifits, but we go the extra difference because we're slaves to style ;-)