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項目的官方文檔,本人在原文檔內容基礎上整理總結而得,中文翻譯僅供參考,英語不還錯的童鞋,能夠直接去官方查看最新的官方文檔哦!!!若是以爲對你有幫助,不要忘了點贊,評論,轉發喲!!!

相關文章
相關標籤/搜索