
The Tomcat Host Manager application enables you to create, delete, and otherwise manage virtual hosts within Tomcat. This how-to guide is best accompanied by the following pieces of documentation:
The Tomcat Host Manager application is a part of
Tomcat installation, by default available using the following
context: /host-manager. You can use the host manager in the
following ways:
{server}:{port}/host-manager/html.
{server}:{port}/host-manager/text.
Both ways enable you to add, remove, start, and stop virtual hosts. Changes
may be persisted by using the persist command. This document
focuses on the text interface. For further information about the graphical
interface, see
Host Manager App -- HTML Interface.
The description below uses $CATALINA_HOME to refer the
base Tomcat directory. It is the directory in which you installed
Tomcat, for example C:\tomcat9, or
/usr/share/tomcat9.
The Host Manager application requires a user with one of the following roles:
admin-gui - use this role for the graphical web interface.
admin-script - use this role for the scripting web interface.
To enable access to the text interface of the Host Manager application,
either grant your Tomcat user the appropriate role, or create a new one with
the correct role. For example, open
${CATALINA_BASE}/conf/tomcat-users.xml and enter the following:
<user username="test" password="chang3m3N#w" roles="admin-script"/>
No further settings is needed. When you now access
{server}:{port}/host-manager/text/${COMMAND},you are able to
log in with the created credentials. For example:
$ curl -u ${USERNAME}:${PASSWORD} http://localhost:8080/host-manager/text/list
OK - Listed hosts
localhost:If you are using a different realm you will need to add the necessary role to the appropriate user(s) using the standard user management tools for that realm.
The following commands are supported:
In the following subsections, the username and password is assumed to be test:test. For your environment, use credentials created in the previous sections.
Use the list command to see the available virtual hosts on your Tomcat instance.
Example command:
curl -u test:test http://localhost:8080/host-manager/text/list
Example response:
OK - Listed hosts
localhost:Use the add command to add a new virtual host. Parameters used for the add command:
Example command:
curl -u test:test http://localhost:8080/host-manager/text/add?name=www.awesomeserver.com&aliases=awesomeserver.com&appBase/mnt/appDir&deployOnStartup=trueExample response:
add: Adding host [www.awesomeserver.com]Use the remove command to remove a virtual host. Parameters used for the remove command:
Example command:
curl -u test:test http://localhost:8080/host-manager/text/remove?name=www.awesomeserver.comExample response:
remove: Removing host [www.awesomeserver.com]Use the start command to start a virtual host. Parameters used for the start command:
Example command:
curl -u test:test http://localhost:8080/host-manager/text/start?name=www.awesomeserver.comExample response:
OK - Host www.awesomeserver.com startedUse the stop command to stop a virtual host. Parameters used for the stop command:
Example command:
curl -u test:test http://localhost:8080/host-manager/text/stop?name=www.awesomeserver.comExample response:
OK - Host www.awesomeserver.com stoppedUse the persist command to persist a virtual host into server.xml. Parameters used for the persist command:
This functionality is disabled by default. To enable this option, you must
configure the StoreConfigLifecycleListener listener first.
To do so, add the following listener to your server.xml:
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>Example command:
curl -u test:test http://localhost:8080/host-manager/text/persist?name=www.awesomeserver.comExample response:
OK - Configuration persistedExample manual entry:
<Host appBase="www.awesomeserver.com" name="www.awesomeserver.com" deployXML="false" unpackWARs="false">
</Host>