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:html
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:web
Both ways enable you to add, remove, start, and stop virtual hosts. Changes may be presisted 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.数据库
在Tomcat的主机管理应用程序,您能够建立,删除,不然在Tomcat管理虚拟主机。本操做指南最好附有如下文档:apache
在Tomcat的主机管理应用程序是Tomcat安装的一部分,默认状况下能够经过以下的背景:/host-manager。您能够经过如下方式使用主机管理器:tomcat
这两种方式都容许您添加,删除,启动和中止虚拟主机。可使用该persist命令预先进行更改。本文档重点介绍文本界面。有关图形界面的更多信息,请参阅 Host Manager App - HTML界面。bash
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:app
如下描述$CATALINA_HOME用于引用基本Tomcat目录。例如C:/tomcat9,它是您安装Tomcat的目录,或 /usr/share/tomcat9。
Host Manager应用程序要求用户具备如下角色之一:less
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:curl
要启用对Host Manager应用程序的文本界面的访问,请为Tomcat用户授予适当的角色,或者建立具备正确角色的新角色。例如,打开 ${CATALINA_BASE}/conf/tomcat-users.xml并输入如下内容:
<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:
无需进一步设置。如今访问时 {server}:{port}/host-manager/text/${COMMAND},您可使用建立的凭据登陆。例如:
$ curl -u ${USERNAME}:${PASSWORD} http://localhost:8080/host-manager/text/list OK - Listed hosts localhost:
Note that in case you retrieve your users using the DataSourceRealm, JDBCRealm, or JNDIRealm mechanism, add the appropriate role in the database or the directory server respectively.
请注意,若是使用,或 机制检索用户 DataSourceRealm,请分别在数据库或目录服务器中添加适当的角色。 JDBCRealmJNDIRealm
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.
支持如下命令:
在如下小节中,假定用户名和密码为 test:test。对于您的环境,请使用前面部分中建立的凭据。
Use the list command to see the available virtual hosts on your Tomcat instance.
使用list命令查看Tomcat实例上的可用虚拟主机。
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:
使用add命令添加新的虚拟主机。用于add命令的参数:
curl -u test:test http://localhost:8080/host-manager/text/add?name=www.awesomeserver.com&aliases=awesomeserver.com&appBase/mnt/appDir&deployOnStartup=true
Example response:
add: Adding host [www.awesomeserver.com]
Use the remove command to remove a virtual host. Parameters used for the remove command:
使用remove命令删除虚拟主机。用于remove命令的参数:
Example command:
curl -u test:test http://localhost:8080/host-manager/text/remove?name=www.awesomeserver.com
Example response:
remove: Removing host [www.awesomeserver.com]
Use the start command to start a virtual host. Parameters used for the start command:
使用stop命令中止虚拟主机。用于stop命令的参数:
Example command:
curl -u test:test http://localhost:8080/host-manager/text/start?name=www.awesomeserver.com
Example response:
OK - Host www.awesomeserver.com started
Use the stop command to stop a virtual host. Parameters used for the stop command:
使用stop命令中止虚拟主机。用于stop命令的参数:
Example command:
curl -u test:test http://localhost:8080/host-manager/text/stop?name=www.awesomeserver.com
Example response:
OK - Host www.awesomeserver.com stopped
Use the persist command to persist a virtual host into server.xml. Parameters used for the persist command:
使用persist命令将虚拟主机持久保存到 server.xml中。用于persist命令的参数:
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:
默认状况下禁用此功能。要启用此选项,必须首先配置StoreConfigLifecycleListener侦听器。为此,请将如下侦听器添加到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.com
Example response:
OK - Configuration persisted
Example manual entry:
<Host appBase="www.awesomeserver.com" name="www.awesomeserver.com" deployXML="false" unpackWARs="false"> </Host>
声明,本文内容来自于Apache基金会官网关于Tomcat项目的官方文档,本人在原文档内容基础上整理总结而得,中文翻译仅供参考,英语不还错的童鞋,能够直接去官方查看最新的官方文档哦!!!若是以为对你有帮助,不要忘了点赞,评论,转发哟!!!