<?xml version="1.0" encoding="UTF-8"?>
<!--
Server是server.xml的根元素,用于创建一个Server实例,默认使用的实现类是:StandardServer
port: Tomcat监听的关闭服务器的端口
shutdown: 关闭服务器的指令字符串
Server内嵌的子元素为Listen、 GlobalNamingResources、Service
-->
<Server port="8005" shutdown="SHUTDOWN">
<!--下面监听器的配置一般不会进行改动操作-->
<!-- 用于以日志形式输出服务器、操作系统、JVM的版本信息-->
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!--用于加载(服务器启动)和销毁(服务器停止) APR。如果找不到APR则会输出日志,并不影响Tomcat的启动-->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--用于避免JRE内存泄漏问题-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<!--用户加载(服务器启动)和销毁(服务器停止) 全局命名服务-->
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<!--用于在Context停止时重建Executor池中的线程,以避免ThreadLocal相关的内存泄漏-->
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- 定义了全局命名的服务,这里面的东西一般不会改动-->
<GlobalNamingResources>
<!--配置了在 tomcat-users.xml文件中配置的用户角色的资源-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<!--
该元素用于创建Service实例,默认使用 org.apache.catalina.core.StandardService。
默认情况下:Tomcat仅指定了Service的名称,值为 Catalina。 Service 可以内嵌的 元素为 : Listener、Executor、Connector、Engine,其中:
- Listener 用于为Service 添加生命周期监听器
- Executor 用于配置Service 共享线程池
- Connector 用于配置 Service 包含的链接器
- Engine 用于配置Service中链接器对应的Servlet容器引擎
-->
<Service name="Catalina">
<!--
共享线程池配置参数:
- name:线程池名称,用于Connector中指定
- namePrefix:所创建的每个线程的名称前缀,一个单独的线程名称为namePrefix+threadNumber。
- maxThreads:池中最大线程数
- minSpareThreads:活跃线程数,也就是核心池线程数,这些线程不会被销毁,会一直存在。
- maxIdleTime:线程空闲时间,超过该时间后,空闲线程会被销毁,默 认值为6000(1分钟),单位毫秒。
- maxQueueSize:在被执行前最大线程排队数目,默认为Int的最大值,也就是广义的无限。除非特殊情况,这个值不需要更改, 否则会有请求不会被处理的情况发生。
- prestartminSpareThreads:启动线程池时是否启动 minSpareThreads部分线程。默认值为false,即不启动。
- threadPriority:线程池中线程优先级,默认值为5,值从1到10。
- className:线程池实现类,未指定情况下,默认实现类为org.apache.catalina.core.StandardThreadExecutor。如果想使用自定义线程池首先需要实现org.apache.catalina.Executor接口
如果不配置共享线程池,那么 Catalina 各组件在用到线程池时会独立创建。
-->
<Executor
name="tomcatThreadPool"
namePrefix="catalina-exec-"
maxThreads="150"
minSpareThreads="4"/>
<!--
Connector 用于创建链接器实例。默认情况下,server.xml 配置了两个链接器,一个支 持HTTP协议,一个支持AJP协议。因此大多数情况下,我们并不需要新增链接器配置, 只是根据需要对已有链接器进行优化。
属性说明:
1. port:端口号,Connector 用于创建服务端Socket 并进行监听, 以等待客户端请求 链接。如果该属性设置为0,Tomcat将会随机选择一个可用的端口号给当前Connector 使用。
2. protocol: 当前Connector支持的访问协议。 默认为 HTTP/1.1,并采用自动切换机制选择一个基于JAVA NIO 的链接器或者基于本地APR的链接器(根据本地是否含有 Tomcat的本地库判定)
如果不希望采用上述自动切换的机制, 而是明确指定协议, 可以使用以下值:
HTTP可以采用协议
org.apache.coyote.http11.Http11NioProtocol非阻塞式Java NIO链接器
org.apache.coyote.http11.Http11Nio2Protocol非阻塞式JAVA NIO2链接器
org.apache.coyote.http11.Http11AprProtocol APR链接器
AJP可以采用的协议:
org.apache.coyote.ajp.AjpNioProtocol非阻塞式Java NIO链接器 org.apache.coyote.ajp.AjpNio2Protocol非阻塞式JAVA NIO2链接器 org.apache.coyote.ajp.AjpAprProtocol APR链接器
3. connectionTimeOut:Connector 接收链接后的等待超时时间, 单位为 毫秒。 -1 表 示不超时
4. redirectPort:当前Connector不支持SSL请求,接收到了一个请求,并且也符合security-constraint 约束,需要SSL传输,Catalina自动将请求重定向到指定的端口
5. executor:指定共享线程池的名称, 也可以通过maxThreads、minSpareThreads 等属性配置内部线程池。
6. URIEncoding:用于指定编码URI的字符编码。Tomcat8.x版本默认的编码为UTF-8,Tomcat7.x版本默认为ISO-8859-1。
-->
<Connector
executor="tomcatThreadPool"
port="8080"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation. The default
SSLImplementation will depend on the presence of the APR/native
library and the useOpenSSL attribute of the
AprLifecycleListener.
Either JSSE or OpenSSL style configuration may be used regardless of
the SSLImplementation selected. JSSE style configuration is used below.
-->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
type="RSA" />
</SSLHostConfig>
</Connector>
-->
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
This connector uses the APR/native implementation which always uses
OpenSSL for TLS.
Either JSSE or OpenSSL style configuration may be used. OpenSSL style
configuration is used below.
-->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
maxThreads="150" SSLEnabled="true" >
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig>
<Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
certificateFile="conf/localhost-rsa-cert.pem"
certificateChainFile="conf/localhost-rsa-chain.pem"
type="RSA" />
</SSLHostConfig>
</Connector>
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!--
Engine是Servlet引擎的顶级元素,内部可以嵌入:Cluster、Listener、Realm、 Valve和Host。
name: 用于指定Engine 的名称, 默认为Catalina 。该名称会影响一部分Tomcat的 存储路径(如临时文件)
defaultHost:默认使用的虚拟主机名称,当客户端请求指向的主机无效时,将交由默认的虚拟主机处理,默认为localhost。
-->
<Engine name="Catalina" defaultHost="localhost">
<!--使用简单的TCP广播的模式来配置Tomcat集群中的session的共享-->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<!--
Host元素用于配置一个虚拟主机,它支持以下嵌入元素:Alias、Cluster、Listener、Valve、Realm、Context。
如果在Engine下配置Realm,那么此配置将在当前Engine下的所有Host中共享。同样,如果在Host中配置Realm , 则在当前Host下的所有Context中共享。Context中的Realm优先级 > Host 的Realm优先级 >Engine中的Realm优先级。
属性说明:
1. name:当前Host通用的网络名称,必须与DNS服务器上的注册信息一致。Engine中包含的Host必须存在一个名称与Engine的defaultHost设置一致。
2. appBase:当前Host的应用基础目录,当前Host上部署的Web应用均在该目录下(可以是绝对目录,相对路径)。默认为webapps。
3. unpackWARs:设置为true,Host在启动时会将appBase目录下war包解压为目录。设置为false,Host将直接从war文件启动
4. autoDeploy:控制tomcat是否在运行时定期检测并自动部署新增或变更的web应用
通过给Host添加别名,我们可以实现同一个Host拥有多个网络名称,配置如下
<Host name="www.web1.com" autoDeploy="true">
<Alias>www.web2.com</Alias>
</Host>
这个时候,我们就可以通过两个域名访问当前Host下的应用(需要确保DNS或hosts中添加了域名的映射配置)
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!--
Context用于配置一个Web应用,默认的配置如下:
1. docBase:Web应用目录或者War包的部署路径。可以是绝对路径,也可以是相对于Host appBase的相对路径
2. path:Web应用的Context 路径。如果我们Host名为localhost,则该web应用访问的根路径为 http://localhost:8080/myApp
它支持的内嵌元素为:CookieProcessor,Loader,Manager,Realm,Resources,WatchedResource,JarScanner,Valve。
-->
<Context docBase="D:\servlet_project03" path="/myApp"/>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
评论区