Tomcat-核⼼配置详解-server.xml

17 篇文章 0 订阅

Tomcat -server.xml结构

<!--
Server 根元素,创建⼀个Server实例,⼦标签有 Listener、 GlobalNamingResources、
Service 中有 Connector    Engine  Host 
-->
<?xml version="1.0" encoding="UTF-8"?>

<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <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>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define an 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 an 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" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <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 name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- 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 &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

Server 标签

<!--
port:关闭服务器的监听端⼝
shutdown:关闭服务器的指令字符串
className指定实现org.apache.catalina.Server接口的类.默认值为org.apache.catalina.core.StandardServer
-->
<Server port="8005" shutdown="SHUTDOWN">
<!-- 以⽇志形式输出服务器 、操作系统、 JVM的版本信息 -->
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <!-- 加载(服务器启动) 和 销毁 (服务器停⽌) APR。 如果找不到APR库, 则会输出⽇志, 并
不影响 Tomcat启动 -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <!-- 避免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" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
       GlobalNamingResources 中定义了全局命名服务
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <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>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
   <Service/>
   ...
   
</Server>

Service 标签


<!--
  name 服务名称
  className 指定实现org.apahce.catalina.Service接口的类.默认为org.apahce.catalina.core.StandardService
  name定义Service的名字
    <Service name="Catalina">
   <Service name="Apache">
   第一个<Service>处理所有直接由Tomcat服务器接收的web客户请求.
   第二个<Service>处理所有由Apahce服务器转发过来的Web客户请求 .
   Service是一组Connector的集合
它们共用一个Engine来处理所有Connector收到的请求
该标签⽤于创建 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">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    执行器-Executor ,定义一个共享的线程池 给Connector中的使用
    maxThreads-最大线程数量
    minSpareThreads-最小线程数量
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    连接器
    端口号
    协议
    超时时间
    重定向端口号
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    连接器 使用线程池
    端口号
    协议
    超时时间
    重定向端口号
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define an 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.
    -->
    <!--
    https的Connector配置
    <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 an 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
    AJP 协议连接端口 协议 重定向的端口号
    -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack
           Realm(表示存放用户名,密码及role的数据库)
           指定Realm使用的类名,此类必须实现org.apache.catalina.Realm接口
           -->
      <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 name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- 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(功能与Logger差不多,其prefix和suffix属性解释和Logger 中的一样)
            className 指定Valve使用的类名,如用org.apache.catalina.valves.AccessLogValve类可以记录应用程序的访问信息
            directory 指定log文件存放的位置
            pattern 有两个值,common方式记录远程主机名或ip地址,用户名,日期,第一行请求的字符串,HTTP响应代码,发送的字节数。
            combined方式比common方式记录的值更多
             -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
Executor标签

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    执行器-Executor ,定义一个共享的线程池 给Connector中的使用

    <Service> 下添加如下配置:
    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接⼝
    <Executor name="commonThreadPool"
        namePrefix="thread-exec-"
        maxThreads="200"
        minSpareThreads="100"
        maxIdleTime="60000"
        maxQueueSize="Integer.MAX_VALUE"
        prestartminSpareThreads="false"
        threadPriority="5"
        className="org.apache.catalina.core.StandardThreadExecutor"/>
-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->
Connector 标签

Connector 标签⽤于创建链接器实例
默认情况下, server.xml 配置了两个链接器,⼀个⽀持HTTP协议,⼀个⽀持AJP协议
⼤多数情况下,我们并不需要新增链接器配置,只是根据需要对已有链接器进⾏优化

    <!-- 
   port:端⼝号, Connector ⽤于创建服务端Socket 并进⾏监听, 以等待客户端请求链接。如果该属性设置
    为0, Tomcat将会随机选择⼀个可⽤的端⼝号给当前Connector 使⽤
    protocol:
    当前Connector ⽀持的访问协议。 默认为 HTTP/1.1 , 并采⽤⾃动切换机制选择⼀个基于 JAVA
    NIO 的链接器或者基于本地APR的链接器(根据本地是否含有Tomcat的本地库判定)
    connectionTimeOut:
    Connector 接收链接后的等待超时时间, 单位为 毫秒。 -1 表示不超时。
    redirectPort:
    当前Connector 不⽀持SSL请求, 接收到了⼀个请求, 并且也符合security-constraint 约束,
    需要SSL传输, Catalina⾃动将请求重定向到指定的端⼝。
    executor:
    指定共享线程池的名称, 也可以通过maxThreads、 minSpareThreads 等属性配置内部线程池
    URIEncoding: ⽤于指定编码URI的字符编码, Tomcat8.x版本默认的编码为 UTF-8 , Tomcat7.x版本默认为ISO-8859-1
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

示例


<Connector port="8080"
protocol="HTTP/1.1"
executor="commonThreadPool"
maxThreads="1000"
minSpareThreads="100"
acceptCount="1000"
maxConnections="1000"
connectionTimeout="20000"
compression="on"
compressionMinSize="2048"
disableUploadTimeout="true"
redirectPort="8443"
URIEncoding="UTF-8" />
Engine标签

表示Servlet引擎
每个Service元素只能有一个Engine元素.处理在同一个中所有元素接收到的客户请求.由org.apahce.catalina.Engine接口定义.

一个“Engine”(引擎)代表处理每个请求的入口点(在Catalina内)。这个Tomcat的标准独立引擎实现分析包含在请求中的HTTP头信息,并将请求传送到适当的主机或虚拟主机上。


Host标签

Host 标签⽤于配置⼀个虚拟主机


<!--
Host 标签⽤于配置⼀个虚拟主机
www.qq.com
www.baidu.com
一个Tomcat可以有多个Host站点
name host名称
webapps 可运行的代码放在哪进而
unpackWARs  解压War包
autoDeploy 自动部署
-->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- 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(功能与Logger差不多,其prefix和suffix属性解释和Logger 中的一样)
            className 指定Valve使用的类名,如用org.apache.catalina.valves.AccessLogValve类可以记录应用程序的访问信息
            directory 指定log文件存放的位置
            pattern 有两个值,common方式记录远程主机名或ip地址,用户名,日期,第一行请求的字符串,HTTP响应代码,发送的字节数。
            combined方式比common方式记录的值更多
             -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

        <!--
      docBase: Web应⽤⽬录或者War包的部署路径。可以是绝对路径,也可以是相对于 Host appBase的相对路径。
    path: Web应⽤的Context 路径。如果我们Host名为localhost, 则该web应⽤访问的根路径为:
        http://localhost:8080/web_demo。
-->
      </Host>
Context标签

Context 标签⽤于配置⼀个Web应⽤,如下

       <!--
Context,对应于一个Web App
             path : 该Context的路径名是"",故该Context是该Host的默认Context
             docBase : 该Context的根目录是webapps/mycontext/
                reloadable:如果这个属性设为true, Tomcat服务器在运行状态下会监视在WEB-INF/classes和Web-INF/lib目录CLASS文件的改运.如果监视到有class文件 被更新,服务器自重新加载Web应用
                useNaming:指定是否支持JNDI,默认值为了true 
                cookies指定是否通过Cookies来支持Session,默认值为true
                -->
<Context docBase="/Users/yingdian/web_demo" path="/web3"></Context>

<Context path="/benxxx" docBase="/webserver/webapps/benbox-manager" reloadable="false" />

        <Context path="/benboxxt" docBase="/webserver/webapps/benboxxxt" reloadable="false" />

完整配置
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<!--
定义服务器关闭时监听的的端口port= 8005
SHUTDOWN 关闭服务器的指令
className指定实现org.apache.catalina.Server接口的类.默认值为org.apache.catalina.core.StandardServer
-->
<Server port="8005" shutdown="SHUTDOWN">
  <!--以日志的形式输出出服务器 、操作系统、 JVM的版本信息-->
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <!--服务器启动 与销毁时加载 APR,如果没有APR,则会输出日志 不影响TOMCAT启动与销毁-->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <!--监听jre内存泄露,避免JRE内在泄露-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <!--加载 全局资源生命周期监听器-->
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <!--在Conect停止时,重建executor中的线程,以避免ThreadLocal内存泄露-->
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
       全局的JNDI资源
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
         全局命名服务
    -->
    <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>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
<!--
  name 服务名称
  className 指定实现org.apahce.catalina.Service接口的类.默认为org.apahce.catalina.core.StandardService
  name定义Service的名字
    <Service name="Catalina">
   <Service name="Apache">
   第一个<Service>处理所有直接由Tomcat服务器接收的web客户请求.
   第二个<Service>处理所有由Apahce服务器转发过来的Web客户请求 .
   Service是一组Connector的集合
它们共用一个Engine来处理所有Connector收到的请求
该标签⽤于创建 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">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    执行器-Executor ,定义一个共享的线程池 给Connector中的使用
    maxThreads-最大线程数量
    minSpareThreads-最小线程数量
    默认情况下, Service 并未添加共享线程池配置。 如果我们想添加⼀个线程池, 可以在
    <Service> 下添加如下配置:
    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接⼝
    <Executor name="commonThreadPool"
        namePrefix="thread-exec-"
        maxThreads="200"
        minSpareThreads="100"
        maxIdleTime="60000"
        maxQueueSize="Integer.MAX_VALUE"
        prestartminSpareThreads="false"
        threadPriority="5"
        className="org.apache.catalina.core.StandardThreadExecutor"/>
-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
   port:端⼝号, Connector ⽤于创建服务端Socket 并进⾏监听, 以等待客户端请求链接。如果该属性设置
    为0, Tomcat将会随机选择⼀个可⽤的端⼝号给当前Connector 使⽤
    protocol:
    当前Connector ⽀持的访问协议。 默认为 HTTP/1.1 , 并采⽤⾃动切换机制选择⼀个基于 JAVA
    NIO 的链接器或者基于本地APR的链接器(根据本地是否含有Tomcat的本地库判定)
    connectionTimeOut:
    Connector 接收链接后的等待超时时间, 单位为 毫秒。 -1 表示不超时。
    redirectPort:
    当前Connector 不⽀持SSL请求, 接收到了⼀个请求, 并且也符合security-constraint 约束,
    需要SSL传输, Catalina⾃动将请求重定向到指定的端⼝。
    executor:
    指定共享线程池的名称, 也可以通过maxThreads、 minSpareThreads 等属性配置内部线程池
    URIEncoding:
⽤   于指定编码URI的字符编码, Tomcat8.x版本默认的编码为 UTF-8 , Tomcat7.x版本默认为ISO-8859-1

<Connector port="8080"
              protocol="HTTP/1.1"
              executor="commonThreadPool"  可以指定自己的线程池,
              maxThreads="1000"
              minSpareThreads="100"
              acceptCount="1000"             接收请求与maxThreads保持一致
              maxConnections="1000"
              connectionTimeout="20000"         连接超时
              compression="on"              要不要启动gzip压缩
              compressionMinSize="2048"      压缩最小大小
              disableUploadTimeout="true"         禁用上传超时时间
              redirectPort="8443"                重定向
              URIEncoding="UTF-8" />
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    连接器 使用线程池
    端口号
    协议
    超时时间
    重定向端口号
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define an 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.
    -->
    <!--
    https的Connector配置
    <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 an 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
    AJP 协议连接端口 协议 重定向的端口号
    -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->

    <!--
    Engine:Servlet引擎
   class:org.apache.catalina.core.StandardEngine
   name: ⽤于指定Engine 的名称, 默认为Catalina
    defaultHost:默认使⽤的虚拟主机名称, 当客户端请求指向的主机⽆效时, 将交由默认的虚拟主机处理,默认为localhost
每个Service元素只能有一个Engine元素.处理在同一个<Service>中所有<Connector>元素接收到的客户请求.
由org.apahce.catalina.Engine接口定义.

localhost表示<Host>标签中的name
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      集群
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack
           Realm(表示存放用户名,密码及role的数据库)
           指定Realm使用的类名,此类必须实现org.apache.catalina.Realm接口
           验证安全
           -->
      <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 标签⽤于配置⼀个虚拟主机
www.qq.com
www.baidu.com
一个Tomcat可以有多个Host站点
name host名称
webapps 可运行的代码放在哪进而
unpackWARs  解压War包
autoDeploy 自动部署
-->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- 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(功能与Logger差不多,其prefix和suffix属性解释和Logger 中的一样)
            className 指定Valve使用的类名,如用org.apache.catalina.valves.AccessLogValve类可以记录应用程序的访问信息
            directory 指定log文件存放的位置
            pattern 有两个值,common方式记录远程主机名或ip地址,用户名,日期,第一行请求的字符串,HTTP响应代码,发送的字节数。
            combined方式比common方式记录的值更多
             -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

        <!--
      docBase: Web应⽤⽬录或者War包的部署路径。可以是绝对路径,也可以是相对于 Host appBase的相对路径。
    path: Web应⽤的Context 路径。如果我们Host名为localhost, 则该web应⽤访问的根路径为:
        http://localhost:8080/web_demo。
-->
      </Host>
    </Engine>
  </Service>
</Server>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值