Virtual Hosting and Tomcat
Table of Contents
For the sake of this how-to, assume you have a development host with two
stimpy. Let's also assume
one instance of Tomcat running, so
$CATALINA_HOME refers to
wherever it's installed, perhaps
Also, this how-to uses Unix-style path separators and commands; if you're on Windows modify accordingly.
At the simplest, edit the Engine portion
server.xml file to look like this:
<Engine name="Catalina" defaultHost="ren"> <Host name="ren" appBase="renapps"/> <Host name="stimpy" appBase="stimpyapps"/> </Engine>
Note that the directory structures under the appBase for each host should not overlap each other.
Consult the configuration documentation for other attributes of the Engine and Host elements.
Create directories for each of the virtual hosts:
mkdir $CATALINA_HOME/renapps mkdir $CATALINA_HOME/stimpyapps
Configuring Your Contexts
Contexts are normally located underneath the appBase directory. For
example, to deploy the
foobar context as a war file in
ren host, use
$CATALINA_HOME/renapps/foobar.war. Note that the
default or ROOT context for
ren would be deployed as
$CATALINA_HOME/renapps/ROOT.war (WAR) or
docBase for a context should never be
the same as the
appBase for a host.
context.xml - approach #1
Within your Context, create a
META-INF directory and then
place your Context definition in it in a file named
This makes deployment easier, particularly if you're distributing a WAR
context.xml - approach #2
Create a structure under
corresponding to your virtual hosts, e.g.:
mkdir $CATALINA_HOME/conf/Catalina/ren mkdir $CATALINA_HOME/conf/Catalina/stimpy
Note that the ending directory name "Catalina" represents the
name attribute of the
Engine element as shown above.
Now, for your default webapps, add:
If you want to use the Tomcat manager webapp for each host, you'll also need to add it here:
cd $CATALINA_HOME/conf/Catalina cp localhost/manager.xml ren/ cp localhost/manager.xml stimpy/
Defaults per host
You can override the default values found in
conf/web.xml by specifying the new values in files
from the host specific xml directory.
Following our previous example, you could use
to customize the defaults for all webapps that are deployed in the virtual
Consult the configuration documentation for other attributes of the Context element.