Tomcat – Adding a docBase for Virtual Host using the Tomcat Virtual Host Manager

tomcattomcat7

In the Tomcat Virtual Host Manager there is an option to add a virtual host with options for:

Name
Aliases
App base
AutoDeploy
DeployOnStartup
DeployXML
UnpackWARs
Manager App

However there doesn't appear to be an option to set the docBase for a virtual host as I have done previously when adding them manually in the XML configuration file:

<Host name="[my_domain_name]" appBase="webapps">
   <Context path="" docBase="[path_to_my_site]" />
</Host>

Is there any way to add this via the manager, or if not, what would the default docBase end up being?

Thanks.

N.B. I'm using Tomcat 7

Best Answer

There is no docBase attribute for an Host. There is one for the context as you can see in your snippet. Per the documentation :

The Document Base (also known as the Context Root) directory for this web application, or the pathname to the web application archive file (if this web application is being executed directly from the WAR file). You may specify an absolute pathname for this directory or WAR file, or a pathname that is relative to the appBase directory of the owning Host.

(see Tomcat 7.0.x documentation)

To declare a personnalised docbase, you will have to set it in all context declaration for the host. (As a side note, it is strongly discouraged to declare context in web.xml, you should add an xml file in the folder conf/<engine-name>/<host> )

As an alternative, seeing as you have an appBase attribute on your host, you can just deploy your war in that path and the doc base will then be the path to your war (expended or not following the other attributes).

For exemple, let's say we have an host in server.xml like :

<Host name="exemple.org" appBase="webapps/exemple.org">
</Host>

andan application i want to deploy to exemple.org/appli. Either I add a file appli.xml in conf/Catalina/exemple.org/ which content is :

<Context docBase="<path/to/war>" ... />

Or I put the war (named appli.war) in webapps/exemple.org/

Again see Tomcat Documentation for all the details.