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:

  • 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:

  • 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管理虚拟主机。本操作指南最好附有以下文档:

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

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

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

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

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:

  • 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应用程序要求用户具有以下角色之一:

  • 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:

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

转载于:https://my.oschina.net/aibinxiao/blog/2253369

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值