码迷,mamicode.com
首页 > 其他好文 > 详细

Tmocat的service.xml配置文件详解(含中文翻译)

时间:2018-07-28 18:17:24      阅读:1466      评论:0      收藏:0      [点我收藏+]

标签:logs   writing   simple   ble   document   属性   虚拟主机   efault   中文翻译   

Tmocat的service.xml配置文件
英文原版
中文手译
<?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
 
 
  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.
-->
 
<!--################Server################################-->
<!-- 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
-->
<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>
 
 
 
 
 
 
 
 
 
 
 
<!--#################Service###############################-->
  <!-- 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"/>
    -->
 
 
 
 
 
 
 
 
 
 
 
 
<!--#################Connector###############################-->
    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         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" URLEncoding="utf-8"/>
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <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 that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
         documentation -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->
 
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<!--##############Engine##################################-->
    <!-- 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###############################-->
 
      <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>
 
<?xml version = "1.0" encoding = ‘uft-8‘?>
<!--
  在一个或多个贡献者许可协议下授权给Apache软件基金会(ASF)。
 请参阅通知文件分发的关于版权所有权的其他信息。Apache软件基金会
 在Apache许可证(2.0)下授权该文件给您。除非符合许可证,否则不得
 使用此文件。你可以在
 
 
 获得一个许可证的副本。
 除非适用法律要求或书面同意,在许可证下分发的软件在“以此类推”的基础
 上分发,无论任何类型的保证或条件,无论明示还是暗示。查看许可证下限
 定的特定语言和权限的许可证。
-->
 
 
 
 
<!--###################Server#####################-->
<!-- 注意:一个“服务器”他本身不是一个“容器”,所以你不能在这个级别上
 定义诸如“Valves”子组件。
 文件在/docs/.config/service.html下
-->
<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" />
 
<!-- 全面的JNDI(Java naming and directory interface)资源
  文件在/docs/jndi-resources-howto.html
-->
 <GlobalNamingResources>
    <!-- 可编辑用户数据,也可以由UserDatabaseRealm认证用户。
    -->
    <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>
 
<!--<Server>顶层容器
 1.Server的主要任务:
    提供一个接口让客户端能够访问到这个Service集合,同时维护它所包含
的所有的Service的声明周期,包括如何初始化、如何结束服务、如何找到
客户端要访问的Service。
 2.Server的属性:
  • shutdown属性,关闭server的指令
  • port属性,Server接受关闭指令的端口号,值为-1表示禁用关闭指令。
 2.Server的特点:
  • 一个Server可以包含多个Service
-->
 
<!--#################Service#######################-->
  <!-- 一个“Service”是一个或多个“Connectors”的集合,这些“Connectors”共享
一个容器。“Service”本身不是一个“Container”,所以你不能在这一级别上定义诸
如“Valves”的子组件。
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">
 
<!--这些Connector可以使用共享的执行器,可以定义一个或多个命名线程池-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->
 
<!--<Service>
 1.Service的主要任务:
    提供对外服务,将Connector和Engine组装在一起。
 2.Service的属性:
  • name属性,用于区分不同的Service
 3.特点
  • 一个Server可以包含多个Service,不同的Service用来监听不同的端口。
  • 一个Service可以包含多个Connector,但是只能包含一个Engine。
-->
 
<!--################Connector#########################-->
<!--一个Connector代表一个端点,通过该端点接受请求返回响应。文件在: 
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
在端口8080上定义一个没有SSL协议/基于TLS的HTTP1.1协议的Connector
-->
 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URLEncoding="utf-8"/>
<!--一个Connector使用共享的线程池-->
<!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
<!-- 在端口8443定义一个 SLL协议/基于TLS的HTTP1.1协议
这个连接器使用需要JSSE(Java安全套接字扩展)配置的NIO实现。
当使用APR或原生实现时,需要Open SSL的样式配置,如在APR或
本地文档所描述的。-->
<!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
-->
 
<!--在8009端口定义一个AJP1.3协议的Connector-->
  <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
 
<!--<Connector>
 1.Connector的主要任务:
    接受连接请求,创建Reuqest和Response对象用于请求交换数据,然后将产生的
Request和Response对象传给Engine并分配线程让Engine来处理请求。
 2.Connector的属性:
  • port属性,设置监听端口
  • protocol属性,设置协议
  • connectTimeout属性,设置连接超时时间
  • redirectPort属性,请求重定向(当强求https请求而请求http时重定向)
 3.特点
  • 此处定义了两个Connector,需要注意的是Tomcat Port 8009 与AJP13协议。
  • 简述AJP协议的特性:AJP协议负责Tomcat和其他的HTTP服务器(如Apache)建立连接;因为Tomcat用户Servlet/Jsp容器,对动态资源的处理较快,但对静态资源的处理较慢。相比之下,Apache和IIS等HTTP服务器对静态资源处理较快。所有:常常将Tomcat与Apache等集成,前者作Servlet容器,后者处理静态资源,而AJP协议便负Tomcat和Apache的连接。
  • 一个Service可以包含多个Connector
-->
 
<!--#################Engine###############################-->
<!-- 一个Engine代表处理每一个请求的入口点(在Calalina内,我们定义的Service内)
为了Tomcat的独立,Engine实现了分析请求包含的HTTP头部并传递给适当的
主机(虚拟主机)上。
 Documentation at /docs/config/engine.html -->
 
<!--你应该设置JVM Route以支持通过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"/>
      -->
 
<!-- 使用LockOutRealm阻止试图通过蛮力法攻击来猜测用户密码
<Realm className="org.apache.catalina.realm.LockOutRealm">
 <!-- 该领域使用全局JNDI资源下在密钥“UserDatabase”中配置的用户数据库。
对该UserDatabase执行的任何编辑都可以立即对该领域使用。
 -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
 
<!--<Engine>
 1.Engine的主要任务:
    处理接受的请求
 2.Engine的属性:
  • name属性,用于记录日志和错误信息
  • defaultHost属性,用于指定的host进行处理,必须与Host组件的name属性匹配
 3.特点
  • 一个Service只能包含一个Engine
 
 
<!--#################Host###############################-->
 
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
 
     <!-- SingleSignOn valve, Web应用程序间的共享认证
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->
 
        <!-- Access日志处理所有示例。
             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" />
 
1.Host的主要任务:
    运行多个Web应用(一个Context代表一个Web应用),并负责安装、展开、启动和结束每个Web应用。
 2.Host的属性:
  • name属性,用于指定虚拟主机名(需要在DNS服务器注册的)
  • appBase属性,War文件所在目录
  • unpackWARs属性, 是否解压War文件
  • autoDeploy属性,是否自动部署(Tomcat运行时定期检查新的Web应用)
  • deployOnStartup属性,启动时检查Web的更新,检测到的所有应用是为新应用,当有应用更新时会出发应用重新部署。
 3.特点
  • 一个Engine可以包含多个Host
 
 
1.Context的主要任务:
    在特定虚拟主机上运行的一个Web应用。每个Web应用基于WAR文件,或WAR文件解压后对应的目录(这里称为应用目录)。
 2.特点
  • Context是Host的子容器,每个Host中可以定义任意多的Context元素。
 
      </Host>
    </Engine>
  </Service>
</Server
1、整体关系
核心组件之间的整体关系,在上一部分有所介绍,这里总结一下:
Server元素在最顶层,代表整个Tomcat容器;一个Server元素中可以有一个或多个Service元素。
Service在Connector和Engine外面包了一层,把它们组装在一起,对外提供服务。一个Service可以包含多个Connector,但是只能包含一个Engine;Connector接收请求,Engine处理请求。
Engine、Host和Context都是容器,且 Engine包含Host,Host包含Context。每个Host组件代表Engine中的一个虚拟主机;每个Context组件代表在特定Host上运行的一个Web应用。

2、如何确定请求由谁处理?

当请求被发送到Tomcat所在的主机时,如何确定最终哪个Web应用来处理该请求呢?

(1)根据协议和端口号选定Service和Engine

Service中的Connector组件可以接收特定端口的请求,因此,当Tomcat启动时,Service组件就会监听特定的端口。在第一部分的例子中,Catalina这个Service监听了8080端口(基于HTTP协议)和8009端口(基于AJP协议)。当请求进来时,Tomcat便可以根据协议和端口号选定处理请求的Service;Service一旦选定,Engine也就确定。
通过在Server中配置多个Service,可以实现通过不同的端口号来访问同一台机器上部署的不同应用。

(2)根据域名或IP地址选定Host

Service确定后,Tomcat在Service中寻找名称与域名/IP地址匹配的Host处理该请求。如果没有找到,则使用Engine中指定的defaultHost来处理该请求。在第一部分的例子中,由于只有一个Host(name属性为localhost),因此该Service/Engine的所有请求都交给该Host处理。

(3)根据URI选定Context/Web应用

这一点在Context一节有详细的说明:Tomcat根据应用的 path属性与URI的匹配程度来选择Web应用处理相应请求,这里不再赘述。

(4)举例

以请求http://localhost:8080/app1/index.html为例,首先通过协议和端口号(http和8080)选定Service;然后通过主机名(localhost)选定Host;然后通过uri(/app1/index.html)选定Web应用。
一个Server可以包含多个Service,不同的Service用来监听不同的端口。
一个Service可以包含多个Connector,但是只能包含一个Engine。
Tomcat可以提供多个Server
Server:对外提供接口(一个Server可以有多个Service)
Service:对外提供服务(一个Service可以包含多个Connector,但是只能包含一个Engine)
Connector:接受客户端请求(一个Service可以包含多个Connector)
Engine:处理接受进来的请求(一个Service只能包含一个Engine)
Host:运行Web应用程序(一个Engine至少有一个Host)
参考链接:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Tmocat的service.xml配置文件详解(含中文翻译)

标签:logs   writing   simple   ble   document   属性   虚拟主机   efault   中文翻译   

原文地址:https://www.cnblogs.com/jdemarryme/p/9382732.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!