gpt4 book ai didi

Tomcat:定义上下文,[Enginename] 和 [Hostname] 是什么?

转载 作者:行者123 更新时间:2023-11-28 21:47:15 25 4
gpt4 key购买 nike

在 Tomcat 的文档中,关于 Defining a context 的部分列出以下选项来定义上下文:

  1. 在应用程序文件内/META-INF/context.xml 的单个文件中。
  2. $CATALINA_BASE/conf/[enginename]/[hostname]/ 目录中的单个文件(扩展名为“.xml”)。上下文路径和版本将从文件的基本名称派生(文件名减去 .xml 扩展名)。此文件将始终优先于打包在 Web 应用程序的 META-INF 目录中的任何 context.xml 文件。
  3. 在主 conf/server.xml 的 Host 元素内。

选项 1 不好,因为它意味着必须对应用程序工件中的值进行硬编码,并且不能轻易更改它们。

选项 3 被文档积极劝阻:

It is NOT recommended to place elements directly in the server.xml file.

这只留给我们选项 2,尤其是如果我们想使用不同的配置多次部署同一应用程序(例如,一个用于生产,一个用于测试),这是唯一的选择。

但是文档没有解释,[enginename][hostname] 应该是什么,或者它们默认是什么。

这些的默认值是什么?我可以在哪里更改它们?

最佳答案

长话短说 [enginename]通常是 Catalina [hostname]通常是 localhost .

简单说明

在 Tomcat 附带的默认配置中,引擎配置在 $CATALINA_HOME/conf/server.xml 中, 在该文件的末尾,您通常会看到类似这样的内容:

<Engine name="Catalina" defaultHost="localhost">

...

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
</Engine>

name <Engine>的属性(property)元素是 enginenamename <Host> 的属性(property)元素是 hostname .

更长的解释

答案可以在两个地方找到,通过阅读 HostEngine Tomcat 文档的页面。

对于 <Engine>元素有趣的值是:

默认主机:

The default host name, which identifies the Host that will process requests directed to host names on this server, but which are not configured in this configuration file. This name MUST match the name attributes of one of the Host elements nested immediately inside.

姓名:

Logical name of this Engine, used in log and error messages. When using multiple Service elements in the same Server, each Engine MUST be assigned a unique name.

对于 <Host>它声明的元素:

姓名:

Usually the network name of this virtual host, as registered in your Domain Name Service server. Regardless of the case used to specify the host name, Tomcat will convert it to lower case internally. One of the Hosts nested within an Engine MUST have a name that matches the defaultHost setting for that Engine. See Host Name Aliases for information on how to assign more than one network name to the same virtual host.

关于Tomcat:定义上下文,[Enginename] 和 [Hostname] 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44181214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com