05-《Apache Tomcat 9 User Guide》之 Host Manager

1.Introduction

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

  • Virtual Hosting How-To for more information about virtual hosting.
  • The Host Container for more information about the underlying xml configuration of virtual hosts and description of attributes.

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

  • Utilizing the graphical user interface, accessible at: {server}:{port}/host-manager/html.
  • Utilizing a set of minimal HTTP requests suitable for scripting. You can access this mode at: {server}:{port}/host-manager/text.

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

  • 虚拟主机如何对有关虚拟主机的详细信息。
  • 主机容器,以获取有关虚拟主机的基础xml配置和属性描述的更多信息。

在Tomcat的主机管理应用程序是Tomcat安装的一部分,默认状况下能够经过以下的背景:/host-manager。您能够经过如下方式使用主机管理器:tomcat

  • 利用图形用户界面,可访问: {server}:{port}/host-manager/html。
  • 利用一组适合脚本编写的最小HTTP请求。您能够访问此模式: {server}:{port}/host-manager/text。

这两种方式都容许您添加,删除,启动和中止虚拟主机。可使用该persist命令预先进行更改。本文档重点介绍文本界面。有关图形界面的更多信息,请参阅 Host Manager App - HTML界面。bash

2.Configuring Manager Application Access

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

  • admin-gui - use this role for the graphical web interface.
  • admin-script - use this role for the scripting web interface.

如下描述$CATALINA_HOME用于引用基本Tomcat目录。例如C:/tomcat9,它是您安装Tomcat的目录,或 /usr/share/tomcat9。

Host Manager应用程序要求用户具备如下角色之一:less

  • admin-gui - 将此角色用于图形Web界面。
  • admin-script - 将此角色用于脚本Web界面。

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

2.1.List of Commands

The following commands are supported:

  • list
  • add
  • remove
  • start
  • stop
  • persist

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。对于您的环境,请使用前面部分中建立的凭据。

2.2.List command

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:

2.3.Add command

Use the add command to add a new virtual host. Parameters used for the add command:

  • String name: Name of the virtual host. REQUIRED
  • String aliases: Aliases for your virtual host.
  • String appBase: Base path for the application that will be served by this virtual host. Provide relative or absolute path.
  • Boolean manager: If true, the Manager app is added to the virtual host. You can access it with the /manager context.
  • Boolean autoDeploy: If true, Tomcat automatically redeploys applications placed in the appBase directory.
  • Boolean deployOnStartup: If true, Tomcat automatically deploys applications placed in the appBase directory on startup.
  • Boolean deployXML: If true, the /META-INF/context.xml file is read and used by Tomcat.
  • Boolean copyXML: If true, Tomcat copies /META-INF/context.xml file and uses the original copy regardless of updates to the application's /META-INF/context.xml file.

使用add命令添加新的虚拟主机。用于add命令的参数:

  • 字符串名称:虚拟主机的名称。须要
  • 字符串别名:虚拟主机的别名。
  • String appBase:此虚拟主机将提供的应用程序的基本路径。提供相对或绝对路径。
  • 布尔管理器:若是为true,则将Manager应用程序添加到虚拟主机。您可使用/ manager上下文访问它。
  • Boolean autoDeploy:若是为true,Tomcat会自动从新部署appBase目录中的应用程序。
  • Boolean deployOnStartup:若是为true,则Tomcat会在启动时自动部署appBase目录中的应用程序。
  • Boolean deployXML:若是为true,则 Tomcat将读取并使用/META-INF/context.xml文件。
  • Boolean copyXML:若是为true,则Tomcat会复制/META-INF/context.xml 文件并使用原始副本,而无论应用程序的/META-INF/context.xml文件的更新如何 。
  • Example command:
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]

2.4.Remove command

Use the remove command to remove a virtual host. Parameters used for the remove command:

使用remove命令删除虚拟主机。用于remove命令的参数:

  • String name: Name of the virtual host to be removed. REQUIRED
  • 字符串名称:要删除的虚拟主机的名称。 须要

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]

2.5.Start command

Use the start command to start a virtual host. Parameters used for the start command:

使用stop命令中止虚拟主机。用于stop命令的参数:

  • String name: Name of the virtual host to be started. REQUIRED
  • 字符串名称:要启动的虚拟主机的名称。 须要

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

2.6.Stop command

Use the stop command to stop a virtual host. Parameters used for the stop command:

使用stop命令中止虚拟主机。用于stop命令的参数:

  • String name: Name of the virtual host to be stopped. REQUIRED
  • 字符串名称:要中止的虚拟主机的名称。 须要

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

2.7.Persist command

Use the persist command to persist a virtual host into server.xml. Parameters used for the persist command:

使用persist命令将虚拟主机持久保存到 server.xml中。用于persist命令的参数:

  • String name: Name of the virtual host to be persist. REQUIRED
  • 字符串名称:要保留的虚拟主机的名称。 须要

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项目的官方文档,本人在原文档内容基础上整理总结而得,中文翻译仅供参考,英语不还错的童鞋,能够直接去官方查看最新的官方文档哦!!!若是以为对你有帮助,不要忘了点赞,评论,转发哟!!!

相关文章
相关标签/搜索