SlideShare a Scribd company logo
解读 server.xml 文件

Tomcat Server 的结构图




该文件描述了如何启动 Tomcat Server
<Server>

    <Listener />

   <GlobaNamingResources>

   </GlobaNamingResources

   <Service>

        <Connector />

       <Engine>

            <Logger />

           <Realm />

               <host>

                   <Logger />

                   <Context />

               </host>
</Engine>

       </Service>

</Server>




                         元素名                                                属性




                                         port
server
                                         shutdown

service                                  name

                                         port

                                         minProcessors

                                         maxProcessors


                                         enableLookups
Connector(表示客户端和 service 之间的连接)

                                         redirectPort


                                         acceptCount


                                         connectionTimeout

Engine(表示指定 service 中的请求处理机,接收和处理来自
                                         defaultHost
Connector 的请求)

Context(表示一个 web 应用程序,通常为 WAR 文件,关于 WAR
                                        docBase
的具体信息见 servlet 规范)

path                                     表示此 web 应用程序的 url 的前缀,这样请求的 url 为 http

                                         这个属性非常重要,如果为 true,则 tomcat 会自动检测应
reloadable
                                         化,自动装载新的应用程序,我们可以在不重起 tomcat 的

host(表示一个虚拟主机)                           name

appBase                                  应用程序基本目录,即存放应用程序的目录

unpackWARs                               如果为 true,则 tomcat 会自动将 WAR 文件解压,否则不
Logger(表示日志,调试和错误信息)                           className

prefix                                         指定 log 文件的前缀

suffix                                         指定 log 文件的后缀

timestamp                                      如果为 true,则 log 文件名中要加入时间,如下例:localho

Realm(表示存放用户名,密码及 role 的数据库)                   className

Valve(功能与 Logger 差不多,其 prefix 和 suffix 属性解释和
                                               className
Logger 中的一样)

directory                                      指定 log 文件存放的位置

                                               有两个值,common 方式记录远程主机名或 ip 地址,用户名
pattern
                                               的字节数。combined 方式比 common 方式记录的值更多



<Server>元素
它代表整个容器,是 Tomcat 实例的顶层元素.由 org.apache.catalina.Server 接口来定义.它包含一个
<Service>元素.并且它不能做为任何元素的子元素.
<!-- 一个“Server”是一个提供完整的 JVM 的独立组件,它可以包含一个或多个
    “Service”实例。服务器在指定的端口上监听 shutdown 命令。

    注意:一个“Server”自身不是一个“Container”(容器),因此在这里你
    不可以定义诸如“Valves”或者“Loggers”子组件
-->
<!-- 启动 Server
    在端口 8005 处等待关闭命令
    如果接受到"SHUTDOWN"字符串则关闭服务器
    -->


测试:
telnet localhost 8005
输入:SHUTDOWN
结果:关闭 tomcat

<Server port="8005" shutdown="SHUTDOWN" debug="0">
1>className 指定实现 org.apache.catalina.Server 接口的类.默认值为
org.apache.catalina.core.StandardServer
2>port 指定 Tomcat 监听 shutdown 命令端口.终止服务器运行时,必须在 Tomcat 服务器所在的机器上发出
shutdown 命令.该属性是必须的.
3>shutdown 指定终止 Tomcat 服务器运行时,发给 Tomcat 服务器的 shutdown 监听端口的字符串.该属性必须
设置


<Service>元素
该元素由 org.apache.catalina.Service 接口定义,它包含一个<Engine>元素,以及一个或多个<Connector>,
这些 Connector 元素共享用同一个 Engine 元素

<!-- 一个“Service”是一个或多个共用一个单独“Container”(容器)的“Connectors”
组合(因此,应用程序在容器中可见)。通常,这个容器是一个“Engine”
       (引擎),但这不是必须的。

       注意:一个“Service”自身不是一个容器,因此,在这个级别上你不可定义
       诸如“Valves”或“Loggers”子组件。
  -->
<!-- Tomcat 的 Standalone Service
Service 是一组 Connector 的集合
它们共用一个 Engine 来处理所有 Connector 收到的请求
-->

   <Service name="Catalina">
   <Service name="Apache">
   第一个<Service>处理所有直接由 Tomcat 服务器接收的 web 客户请求.
   第二个<Service>处理所有由 Apahce 服务器转发过来的 Web 客户请求 .
1>className 指定实现 org.apahce.catalina.Service 接口的类.默认为
org.apahce.catalina.core.StandardService
2>name 定义 Service 的名字



<Connector>元素
由 Connector 接口定义.<Connector>元素代表与客户程序实际交互的给件,它负责接收客户请求,以及向客户返
回响应结果.

<!-- 一个“Connector”(连接器)代表一个请求被接收和应答所需要的端点。每个连
      接器通过相关的“Container”(容器)处理请求。

       默认情况下,一个非 SSL 的 HTTP/1.1 的连接器被绑定在端口 8080。你也可以通过
       根据后面的使用说明并取消第二个连接器入口的注释,在端口 8443 上建立一个
       SSL HTTP/1.1 的连接器。开放 SSL 支持需要下面几步(参见 Tomcat 5 文档中怎样
       配置 SSL 的说明以取得更多的详细信息):
       * 如果你的 JDK 是 1.3 或 1.3 以前的版本,下载安装 JSSE 1.0.2 或以后版本,并放
        置 JAR 文件到“$JAVA_HOME/jre/lib/ext”目录下。
       * 带一个“changeit”的口令值执行:
         %JAVA_HOME%binkeytool -genkey -alias tomcat -keyalg RSA (Windows)
         $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA (UNIX)
        来生成它自己的证书私钥。

       默认情况下,当一个 web 应用程序调用请求时,DNS 查询是可行的。这将对性能造
       成一些不利的影响,因此,你可以将“enableLookups”设置为“false”来关闭 DNS
       查询。当 DNS 查询被关闭时,request.getRemoteHost()将返回包含远程客户 IP 地
       址的字符串。
 -->

<!-- Coyote HTTP/1.1 Connector
className : 该 Connector 的实现类是 org.apache.coyote.tomcat4.CoyoteConnector
port : 在端口号 8080 处侦听来自客户 browser 的 HTTP1.1 请求.如果把 8080 改成 80,则只要输入
http://localhost/即可
    protocol:设定 Http 协议,默认值为 HTTP/1.1
minSpareThreads: 该 Connector 先创建 5 个线程等待客户请求,每个请求由一个线程负责
maxSpareThread:设定在监听端口的线程的最大数目,这个值也决定了服务器可以同时响应客户请求的最大数目.
默认值为 200
    acceptCount : 当现有线程已经达到最大数 75 时,为客户请求排队.当队列中请求数超过 100 时,后来的请
求返回 Connection refused 错误
redirectport : 当客户请求是 https 时,把该请求转发到端口 8443 去
   enableLookups:如果设为 true,表示支持域名解析,可以把 IP 地址解析为主机名.WEB 应用中调用
request.getRemoteHost 方法返回客户机主机名.默认值为 true
   connectionTimeout:定义建立客户连接超时的时间.如果为-1,表示不限制建立客户连接的时间


其它属性略
-->


<Connector port="8080" maxThread="50" minSpareThreads="25"maxSpareThread="75"
enableLookups="false" redirectPort="8443"acceptCount="100" debug="0"
cdisableUploadTimeout="true" />
<Connection port="8009" enableLookups="false" redirectPort="8443" debug="0"
protocol="AJP/1.3" />
第一个 Connector 元素定义了一个 HTTP Connector,它通过 8080 端口接收 HTTP 请求;第二个 Connector 元
素定义了一个 JD Connector,它通过 8009 端口接收由其它服务器转发过来的请求.


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

<!-- 一个“Engine”(引擎)代表处理每个请求的入口点(在 Catalina 内)。这个 Tomcat
       的标准独立引擎实现分析包含在请求中的 HTTP 头信息,并将请求传送到适当的主机
       或虚拟主机上。-->
<!-- Engine 用来处理 Connector 收到的 Http 请求
      它将匹配请求和自己的虚拟主机,并把请求转交给对应的 Host 来处理
      默认虚拟主机是 localhost
      -->



<Engine name="Catalina" defaultHost="localhost" debug="0">
1>className 指定实现 Engine 接口的类,默认值为 StandardEngine
2>defaultHost 指定处理客户的默认主机名,在<Engine>中的<Host>子元素中必须定义这一主机
3>name 定义 Engine 的名字
在<Engine>可以包含如下元素<Logger>, <Realm>, <Value>, <Host>



<Host>元素
它由 Host 接口定义.一个 Engine 元素可以包含多个<Host>元素.每个<Host>的元素定义了一个虚拟主机.它包
含了一个或多个 Web 应用.
<!-- 定义默认的虚拟主机
         注意:XML 模式确认将不能与 Xerces 2.2 同工作。
     -->
<!-- 虚拟主机 localhost
       appBase :指定虚拟主机的目录,可以指定绝对目录,也可以指定相对于<CATALINA_HOME>的相对目
录.如果没有此项,默认为<CATALINA_HOME>/webapps.它将匹配请求和自己的 Context 的路径,并把请求转
交给对应的 Context 来处理
          autoDeploy:如果此项设为 true,表示 Tomcat 服务处于运行状态时,能够监测 appBase 下的文件,如
果有新有 web 应用加入进来,会自运发布这个 WEB 应用
          unpackWARs:如果此项设置为 true,表示把 WEB 应用的 WAR 文件先展开为开放目录结构后再运行.
如果设为 false 将直接运行为 WAR 文件
alias:指定主机别名,可以指定多个别名
        deployOnStartup:如果此项设为 true,表示 Tomcat 服务器启动时会自动发布 appBase 目录下所有
的 Web 应用.如果 Web 应用中的 server.xml 没有相应的<Context>元素,将采用 Tomcat 默认的 Context
      -->


<Host name="localhost" debug="0" appBase="webapps" unpackWARs="true"
autoDeploy="true">
在<Host>元素中可以包含如下子元素
<Logger>, <Realm>, <Value>, <Context>

<Context>元素
它由 Context 接口定义.是使用最频繁的元素.每个<Context 元素代表了运行在虚拟主机上的单个 Web 应用.一
个<Host>可以包含多个<Context>元素.每个 web 应用有唯一
的一个相对应的 Context 代表 web 应用自身.servlet 容器为第一个 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 path="" docBase="mycontext" debug="0"/>


Tomcat Server 处理一个 http 请求的过程
假设来自客户的请求为:
http://localhost:8080/wsota/wsota_index.jsp
1) 请求被发送到本机端口 8080,被在那里侦听的 Coyote HTTP/1.1 Connector 获得
2) Connector 把该请求交给它所在的 Service 的 Engine 来处理,并等待来自 Engine 的回应
3) Engine 获得请求 localhost/wsota/wsota_index.jsp,匹配它所拥有的所有虚拟主机 Host
4) Engine 匹配到名为 localhost 的 Host(即使匹配不到也把请求交给该 Host 处理,因为该 Host 被定义为该
Engine 的默认主机)
5) localhost Host 获得请求/wsota/wsota_index.jsp,匹配它所拥有的所有 Context
6) Host 匹配到路径为/wsota 的 Context(如果匹配不到就把该请求交给路径名为""的 Context 去处理)
7) path="/wsota"的 Context 获得请求/wsota_index.jsp,在它的 mapping table 中寻找对应的 servlet
8) Context 匹配到 URL PATTERN 为*.jsp 的 servlet,对应于 JspServlet 类
9) 构造 HttpServletRequest 对象和 HttpServletResponse 对象,作为参数调用 JspServlet 的 doGet 或
doPost 方法
10)Context 把执行完了之后的 HttpServletResponse 对象返回给 Host
11)Host 把 HttpServletResponse 对象返回给 Engine
12)Engine 把 HttpServletResponse 对象返回给 Connector
13)Connector 把 HttpServletResponse 对象返回给客户 browser

More Related Content

What's hot

Failsafe Mechanism for Yahoo Homepage
Failsafe Mechanism for Yahoo HomepageFailsafe Mechanism for Yahoo Homepage
Failsafe Mechanism for Yahoo Homepage
Kit Chan
 
Replacing Squid with ATS
Replacing Squid with ATSReplacing Squid with ATS
Replacing Squid with ATS
Kit Chan
 
Apache Tomcat 8 Application Server
Apache Tomcat 8 Application ServerApache Tomcat 8 Application Server
Apache Tomcat 8 Application Server
mohamedmoharam
 
Servlets
ServletsServlets
Servlets
Geethu Mohan
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
Tony Fabeen
 
Apache tomcat
Apache tomcatApache tomcat
Apache tomcat
Shashwat Shriparv
 
How to monitor and manage Apache Tomcat
How to monitor and manage Apache TomcatHow to monitor and manage Apache Tomcat
How to monitor and manage Apache Tomcat
Egnyte
 
Tomcat
TomcatTomcat
Scripts Python Dbapi
Scripts Python DbapiScripts Python Dbapi
Scripts Python Dbapi
AkramWaseem
 
The SaltStack Pub Crawl - Fosscomm 2016
The SaltStack Pub Crawl - Fosscomm 2016The SaltStack Pub Crawl - Fosscomm 2016
The SaltStack Pub Crawl - Fosscomm 2016
effie mouzeli
 
青云CoreOS虚拟机部署kubernetes
青云CoreOS虚拟机部署kubernetes 青云CoreOS虚拟机部署kubernetes
青云CoreOS虚拟机部署kubernetes
Zhichao Liang
 
Introduction to Apache Tomcat 7 Presentation
Introduction to Apache Tomcat 7 PresentationIntroduction to Apache Tomcat 7 Presentation
Introduction to Apache Tomcat 7 Presentation
Tomcat Expert
 
Faster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzzFaster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzz
JBug Italy
 
Kubernetes #4 volume &amp; stateful set
Kubernetes #4   volume &amp; stateful setKubernetes #4   volume &amp; stateful set
Kubernetes #4 volume &amp; stateful set
Terry Cho
 
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in UbuntuHow To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
Wirabumi Software
 
Lesson 9. The Apache Web Server
Lesson 9. The Apache Web ServerLesson 9. The Apache Web Server
Lesson 9. The Apache Web Server
webhostingguy
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Tom Croucher
 
Using ngx_lua in UPYUN
Using ngx_lua in UPYUNUsing ngx_lua in UPYUN
Using ngx_lua in UPYUN
Cong Zhang
 
Laravel 5.6 new features and updates
Laravel 5.6  new features and updatesLaravel 5.6  new features and updates
Laravel 5.6 new features and updates
RocketRoute
 
Fluentd v1.0 in a nutshell
Fluentd v1.0 in a nutshellFluentd v1.0 in a nutshell
Fluentd v1.0 in a nutshell
N Masahiro
 

What's hot (20)

Failsafe Mechanism for Yahoo Homepage
Failsafe Mechanism for Yahoo HomepageFailsafe Mechanism for Yahoo Homepage
Failsafe Mechanism for Yahoo Homepage
 
Replacing Squid with ATS
Replacing Squid with ATSReplacing Squid with ATS
Replacing Squid with ATS
 
Apache Tomcat 8 Application Server
Apache Tomcat 8 Application ServerApache Tomcat 8 Application Server
Apache Tomcat 8 Application Server
 
Servlets
ServletsServlets
Servlets
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
 
Apache tomcat
Apache tomcatApache tomcat
Apache tomcat
 
How to monitor and manage Apache Tomcat
How to monitor and manage Apache TomcatHow to monitor and manage Apache Tomcat
How to monitor and manage Apache Tomcat
 
Tomcat
TomcatTomcat
Tomcat
 
Scripts Python Dbapi
Scripts Python DbapiScripts Python Dbapi
Scripts Python Dbapi
 
The SaltStack Pub Crawl - Fosscomm 2016
The SaltStack Pub Crawl - Fosscomm 2016The SaltStack Pub Crawl - Fosscomm 2016
The SaltStack Pub Crawl - Fosscomm 2016
 
青云CoreOS虚拟机部署kubernetes
青云CoreOS虚拟机部署kubernetes 青云CoreOS虚拟机部署kubernetes
青云CoreOS虚拟机部署kubernetes
 
Introduction to Apache Tomcat 7 Presentation
Introduction to Apache Tomcat 7 PresentationIntroduction to Apache Tomcat 7 Presentation
Introduction to Apache Tomcat 7 Presentation
 
Faster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzzFaster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzz
 
Kubernetes #4 volume &amp; stateful set
Kubernetes #4   volume &amp; stateful setKubernetes #4   volume &amp; stateful set
Kubernetes #4 volume &amp; stateful set
 
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in UbuntuHow To Install Openbravo ERP 2.50 MP43 in Ubuntu
How To Install Openbravo ERP 2.50 MP43 in Ubuntu
 
Lesson 9. The Apache Web Server
Lesson 9. The Apache Web ServerLesson 9. The Apache Web Server
Lesson 9. The Apache Web Server
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
 
Using ngx_lua in UPYUN
Using ngx_lua in UPYUNUsing ngx_lua in UPYUN
Using ngx_lua in UPYUN
 
Laravel 5.6 new features and updates
Laravel 5.6  new features and updatesLaravel 5.6  new features and updates
Laravel 5.6 new features and updates
 
Fluentd v1.0 in a nutshell
Fluentd v1.0 in a nutshellFluentd v1.0 in a nutshell
Fluentd v1.0 in a nutshell
 

Viewers also liked

如何一整天有精神,保持微笑
如何一整天有精神,保持微笑如何一整天有精神,保持微笑
如何一整天有精神,保持微笑wensheng wei
 
Treebeard's Unix Cheat Sheet
Treebeard's Unix Cheat SheetTreebeard's Unix Cheat Sheet
Treebeard's Unix Cheat Sheet
wensheng wei
 
数据库系统安全防入侵技术综述
数据库系统安全防入侵技术综述数据库系统安全防入侵技术综述
数据库系统安全防入侵技术综述wensheng wei
 
20 种提升网页速度的技巧
20 种提升网页速度的技巧20 种提升网页速度的技巧
20 种提升网页速度的技巧wensheng wei
 
什么是重要的事情?
什么是重要的事情?什么是重要的事情?
什么是重要的事情?wensheng wei
 
详细介绍什么是Java虚拟机(JVM)介绍资料
详细介绍什么是Java虚拟机(JVM)介绍资料详细介绍什么是Java虚拟机(JVM)介绍资料
详细介绍什么是Java虚拟机(JVM)介绍资料wensheng wei
 
超级入门:JAVA从零开始到HelloWorld
超级入门:JAVA从零开始到HelloWorld超级入门:JAVA从零开始到HelloWorld
超级入门:JAVA从零开始到HelloWorldwensheng wei
 
Java的垃圾回收之算法
Java的垃圾回收之算法Java的垃圾回收之算法
Java的垃圾回收之算法wensheng wei
 
保护数据库服务器加强数据库安全
保护数据库服务器加强数据库安全保护数据库服务器加强数据库安全
保护数据库服务器加强数据库安全wensheng wei
 
Database Security Explained
Database Security ExplainedDatabase Security Explained
Database Security Explained
wensheng wei
 
mysql的字符串函数
mysql的字符串函数mysql的字符串函数
mysql的字符串函数wensheng wei
 
LINUX Admin Quick Reference
LINUX Admin Quick ReferenceLINUX Admin Quick Reference
LINUX Admin Quick Reference
wensheng wei
 
JavaScript高级程序设计(中文优化版)
JavaScript高级程序设计(中文优化版)JavaScript高级程序设计(中文优化版)
JavaScript高级程序设计(中文优化版)wensheng wei
 
LINUX System Call Quick Reference
LINUX System Call Quick ReferenceLINUX System Call Quick Reference
LINUX System Call Quick Reference
wensheng wei
 

Viewers also liked (17)

Subversion FAQ
Subversion FAQSubversion FAQ
Subversion FAQ
 
如何一整天有精神,保持微笑
如何一整天有精神,保持微笑如何一整天有精神,保持微笑
如何一整天有精神,保持微笑
 
Treebeard's Unix Cheat Sheet
Treebeard's Unix Cheat SheetTreebeard's Unix Cheat Sheet
Treebeard's Unix Cheat Sheet
 
数据库系统安全防入侵技术综述
数据库系统安全防入侵技术综述数据库系统安全防入侵技术综述
数据库系统安全防入侵技术综述
 
JVM 学习笔记
JVM 学习笔记JVM 学习笔记
JVM 学习笔记
 
20 种提升网页速度的技巧
20 种提升网页速度的技巧20 种提升网页速度的技巧
20 种提升网页速度的技巧
 
什么是重要的事情?
什么是重要的事情?什么是重要的事情?
什么是重要的事情?
 
创新项目
创新项目创新项目
创新项目
 
详细介绍什么是Java虚拟机(JVM)介绍资料
详细介绍什么是Java虚拟机(JVM)介绍资料详细介绍什么是Java虚拟机(JVM)介绍资料
详细介绍什么是Java虚拟机(JVM)介绍资料
 
超级入门:JAVA从零开始到HelloWorld
超级入门:JAVA从零开始到HelloWorld超级入门:JAVA从零开始到HelloWorld
超级入门:JAVA从零开始到HelloWorld
 
Java的垃圾回收之算法
Java的垃圾回收之算法Java的垃圾回收之算法
Java的垃圾回收之算法
 
保护数据库服务器加强数据库安全
保护数据库服务器加强数据库安全保护数据库服务器加强数据库安全
保护数据库服务器加强数据库安全
 
Database Security Explained
Database Security ExplainedDatabase Security Explained
Database Security Explained
 
mysql的字符串函数
mysql的字符串函数mysql的字符串函数
mysql的字符串函数
 
LINUX Admin Quick Reference
LINUX Admin Quick ReferenceLINUX Admin Quick Reference
LINUX Admin Quick Reference
 
JavaScript高级程序设计(中文优化版)
JavaScript高级程序设计(中文优化版)JavaScript高级程序设计(中文优化版)
JavaScript高级程序设计(中文优化版)
 
LINUX System Call Quick Reference
LINUX System Call Quick ReferenceLINUX System Call Quick Reference
LINUX System Call Quick Reference
 

Similar to 解读server.xml文件

Hybris server-internals
Hybris server-internalsHybris server-internals
Hybris server-internals
Gaurav Kumar
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
Auwal Amshi
 
Tomcat Configuration (1)
Tomcat Configuration (1)Tomcat Configuration (1)
Tomcat Configuration (1)
nazeer pasha
 
Tomcat Server
Tomcat ServerTomcat Server
Tomcat Server
Anirban Majumdar
 
Tomcat configuration
Tomcat configurationTomcat configuration
Tomcat configuration
Dima Gomaa
 
Tomcat 6: Evolving our server
Tomcat 6: Evolving our serverTomcat 6: Evolving our server
Tomcat 6: Evolving our server
Jorge S Cruz Lambert
 
Apache Con NA 2013 - Cassandra Internals
Apache Con NA 2013 - Cassandra InternalsApache Con NA 2013 - Cassandra Internals
Apache Con NA 2013 - Cassandra Internals
aaronmorton
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
bharathiv53
 
weblogic perfomence tuning
weblogic perfomence tuningweblogic perfomence tuning
weblogic perfomence tuning
prathap kumar
 
Apache Cassandra in Bangalore - Cassandra Internals and Performance
Apache Cassandra in Bangalore - Cassandra Internals and PerformanceApache Cassandra in Bangalore - Cassandra Internals and Performance
Apache Cassandra in Bangalore - Cassandra Internals and Performance
aaronmorton
 
Hackingtomcat
HackingtomcatHackingtomcat
Hackingtomcat
Aung Khant
 
Hacking Tomcat
Hacking TomcatHacking Tomcat
Hacking Tomcat
guestc27cd9
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
ssbd6985
 
bjhbj
bjhbjbjhbj
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
Ankit Minocha
 
Web servers
Web serversWeb servers
Web servers
Kuldeep Kulkarni
 
Unit5 servlets
Unit5 servletsUnit5 servlets
Unit5 servlets
Praveen Yadav
 
Integrating tomcat with apache
Integrating tomcat with apacheIntegrating tomcat with apache
Integrating tomcat with apache
govindraj8787
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New Evolution
Allan Huang
 
Apache
ApacheApache

Similar to 解读server.xml文件 (20)

Hybris server-internals
Hybris server-internalsHybris server-internals
Hybris server-internals
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
Tomcat Configuration (1)
Tomcat Configuration (1)Tomcat Configuration (1)
Tomcat Configuration (1)
 
Tomcat Server
Tomcat ServerTomcat Server
Tomcat Server
 
Tomcat configuration
Tomcat configurationTomcat configuration
Tomcat configuration
 
Tomcat 6: Evolving our server
Tomcat 6: Evolving our serverTomcat 6: Evolving our server
Tomcat 6: Evolving our server
 
Apache Con NA 2013 - Cassandra Internals
Apache Con NA 2013 - Cassandra InternalsApache Con NA 2013 - Cassandra Internals
Apache Con NA 2013 - Cassandra Internals
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
 
weblogic perfomence tuning
weblogic perfomence tuningweblogic perfomence tuning
weblogic perfomence tuning
 
Apache Cassandra in Bangalore - Cassandra Internals and Performance
Apache Cassandra in Bangalore - Cassandra Internals and PerformanceApache Cassandra in Bangalore - Cassandra Internals and Performance
Apache Cassandra in Bangalore - Cassandra Internals and Performance
 
Hackingtomcat
HackingtomcatHackingtomcat
Hackingtomcat
 
Hacking Tomcat
Hacking TomcatHacking Tomcat
Hacking Tomcat
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
bjhbj
bjhbjbjhbj
bjhbj
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
Web servers
Web serversWeb servers
Web servers
 
Unit5 servlets
Unit5 servletsUnit5 servlets
Unit5 servlets
 
Integrating tomcat with apache
Integrating tomcat with apacheIntegrating tomcat with apache
Integrating tomcat with apache
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New Evolution
 
Apache
ApacheApache
Apache
 

More from wensheng wei

你会柔软地想起这个校园
你会柔软地想起这个校园你会柔软地想起这个校园
你会柔软地想起这个校园wensheng wei
 
几米语录(1)
几米语录(1)几米语录(1)
几米语录(1)wensheng wei
 
Installation of Subversion on Ubuntu,...
Installation of Subversion on Ubuntu,...Installation of Subversion on Ubuntu,...
Installation of Subversion on Ubuntu,...
wensheng wei
 
高级PHP应用程序漏洞审核技术
高级PHP应用程序漏洞审核技术高级PHP应用程序漏洞审核技术
高级PHP应用程序漏洞审核技术wensheng wei
 
存储过程编写经验和优化措施
存储过程编写经验和优化措施存储过程编写经验和优化措施
存储过程编写经验和优化措施wensheng wei
 
CentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 ZendCentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 Zendwensheng wei
 
Happiness is a Journey
Happiness is a JourneyHappiness is a Journey
Happiness is a Journey
wensheng wei
 
Java JNI 编程进阶
Java JNI 编程进阶     Java JNI 编程进阶
Java JNI 编程进阶 wensheng wei
 
Linux Shortcuts and Commands:
Linux Shortcuts and Commands:Linux Shortcuts and Commands:
Linux Shortcuts and Commands:
wensheng wei
 
Java正则表达式详解
Java正则表达式详解Java正则表达式详解
Java正则表达式详解wensheng wei
 
Linux Security Quick Reference Guide
Linux Security Quick Reference GuideLinux Security Quick Reference Guide
Linux Security Quick Reference Guide
wensheng wei
 
issue35 zh-CN
issue35 zh-CNissue35 zh-CN
issue35 zh-CN
wensheng wei
 
Android模拟器SD Card映像文件使用方法
Android模拟器SD Card映像文件使用方法Android模拟器SD Card映像文件使用方法
Android模拟器SD Card映像文件使用方法wensheng wei
 
如何硬盘安装ubuntu8.10
如何硬盘安装ubuntu8.10如何硬盘安装ubuntu8.10
如何硬盘安装ubuntu8.10wensheng wei
 
ubunturef
ubunturefubunturef
ubunturef
wensheng wei
 
数据库设计方法、规范与技巧
数据库设计方法、规范与技巧数据库设计方法、规范与技巧
数据库设计方法、规范与技巧wensheng wei
 
揭秘全球最大网站Facebook背后的那些软件
揭秘全球最大网站Facebook背后的那些软件揭秘全球最大网站Facebook背后的那些软件
揭秘全球最大网站Facebook背后的那些软件wensheng wei
 
入门-Java运行环境变量的图文教程
入门-Java运行环境变量的图文教程入门-Java运行环境变量的图文教程
入门-Java运行环境变量的图文教程wensheng wei
 

More from wensheng wei (20)

你会柔软地想起这个校园
你会柔软地想起这个校园你会柔软地想起这个校园
你会柔软地想起这个校园
 
几米语录(1)
几米语录(1)几米语录(1)
几米语录(1)
 
我的简历
我的简历我的简历
我的简历
 
Installation of Subversion on Ubuntu,...
Installation of Subversion on Ubuntu,...Installation of Subversion on Ubuntu,...
Installation of Subversion on Ubuntu,...
 
高级PHP应用程序漏洞审核技术
高级PHP应用程序漏洞审核技术高级PHP应用程序漏洞审核技术
高级PHP应用程序漏洞审核技术
 
存储过程编写经验和优化措施
存储过程编写经验和优化措施存储过程编写经验和优化措施
存储过程编写经验和优化措施
 
CentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 ZendCentOS5 apache2 mysql5 php5 Zend
CentOS5 apache2 mysql5 php5 Zend
 
Happiness is a Journey
Happiness is a JourneyHappiness is a Journey
Happiness is a Journey
 
Java JNI 编程进阶
Java JNI 编程进阶     Java JNI 编程进阶
Java JNI 编程进阶
 
Linux Shortcuts and Commands:
Linux Shortcuts and Commands:Linux Shortcuts and Commands:
Linux Shortcuts and Commands:
 
Java正则表达式详解
Java正则表达式详解Java正则表达式详解
Java正则表达式详解
 
Linux Security Quick Reference Guide
Linux Security Quick Reference GuideLinux Security Quick Reference Guide
Linux Security Quick Reference Guide
 
issue35 zh-CN
issue35 zh-CNissue35 zh-CN
issue35 zh-CN
 
Android模拟器SD Card映像文件使用方法
Android模拟器SD Card映像文件使用方法Android模拟器SD Card映像文件使用方法
Android模拟器SD Card映像文件使用方法
 
如何硬盘安装ubuntu8.10
如何硬盘安装ubuntu8.10如何硬盘安装ubuntu8.10
如何硬盘安装ubuntu8.10
 
ubunturef
ubunturefubunturef
ubunturef
 
数据库设计方法、规范与技巧
数据库设计方法、规范与技巧数据库设计方法、规范与技巧
数据库设计方法、规范与技巧
 
揭秘全球最大网站Facebook背后的那些软件
揭秘全球最大网站Facebook背后的那些软件揭秘全球最大网站Facebook背后的那些软件
揭秘全球最大网站Facebook背后的那些软件
 
入门-Java运行环境变量的图文教程
入门-Java运行环境变量的图文教程入门-Java运行环境变量的图文教程
入门-Java运行环境变量的图文教程
 
Java学习路径
Java学习路径Java学习路径
Java学习路径
 

Recently uploaded

Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 

Recently uploaded (20)

Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 

解读server.xml文件

  • 1. 解读 server.xml 文件 Tomcat Server 的结构图 该文件描述了如何启动 Tomcat Server <Server> <Listener /> <GlobaNamingResources> </GlobaNamingResources <Service> <Connector /> <Engine> <Logger /> <Realm /> <host> <Logger /> <Context /> </host>
  • 2. </Engine> </Service> </Server> 元素名 属性 port server shutdown service name port minProcessors maxProcessors enableLookups Connector(表示客户端和 service 之间的连接) redirectPort acceptCount connectionTimeout Engine(表示指定 service 中的请求处理机,接收和处理来自 defaultHost Connector 的请求) Context(表示一个 web 应用程序,通常为 WAR 文件,关于 WAR docBase 的具体信息见 servlet 规范) path 表示此 web 应用程序的 url 的前缀,这样请求的 url 为 http 这个属性非常重要,如果为 true,则 tomcat 会自动检测应 reloadable 化,自动装载新的应用程序,我们可以在不重起 tomcat 的 host(表示一个虚拟主机) name appBase 应用程序基本目录,即存放应用程序的目录 unpackWARs 如果为 true,则 tomcat 会自动将 WAR 文件解压,否则不
  • 3. Logger(表示日志,调试和错误信息) className prefix 指定 log 文件的前缀 suffix 指定 log 文件的后缀 timestamp 如果为 true,则 log 文件名中要加入时间,如下例:localho Realm(表示存放用户名,密码及 role 的数据库) className Valve(功能与 Logger 差不多,其 prefix 和 suffix 属性解释和 className Logger 中的一样) directory 指定 log 文件存放的位置 有两个值,common 方式记录远程主机名或 ip 地址,用户名 pattern 的字节数。combined 方式比 common 方式记录的值更多 <Server>元素 它代表整个容器,是 Tomcat 实例的顶层元素.由 org.apache.catalina.Server 接口来定义.它包含一个 <Service>元素.并且它不能做为任何元素的子元素. <!-- 一个“Server”是一个提供完整的 JVM 的独立组件,它可以包含一个或多个 “Service”实例。服务器在指定的端口上监听 shutdown 命令。 注意:一个“Server”自身不是一个“Container”(容器),因此在这里你 不可以定义诸如“Valves”或者“Loggers”子组件 --> <!-- 启动 Server 在端口 8005 处等待关闭命令 如果接受到"SHUTDOWN"字符串则关闭服务器 --> 测试: telnet localhost 8005 输入:SHUTDOWN 结果:关闭 tomcat <Server port="8005" shutdown="SHUTDOWN" debug="0"> 1>className 指定实现 org.apache.catalina.Server 接口的类.默认值为 org.apache.catalina.core.StandardServer 2>port 指定 Tomcat 监听 shutdown 命令端口.终止服务器运行时,必须在 Tomcat 服务器所在的机器上发出 shutdown 命令.该属性是必须的. 3>shutdown 指定终止 Tomcat 服务器运行时,发给 Tomcat 服务器的 shutdown 监听端口的字符串.该属性必须 设置 <Service>元素 该元素由 org.apache.catalina.Service 接口定义,它包含一个<Engine>元素,以及一个或多个<Connector>, 这些 Connector 元素共享用同一个 Engine 元素 <!-- 一个“Service”是一个或多个共用一个单独“Container”(容器)的“Connectors”
  • 4. 组合(因此,应用程序在容器中可见)。通常,这个容器是一个“Engine” (引擎),但这不是必须的。 注意:一个“Service”自身不是一个容器,因此,在这个级别上你不可定义 诸如“Valves”或“Loggers”子组件。 --> <!-- Tomcat 的 Standalone Service Service 是一组 Connector 的集合 它们共用一个 Engine 来处理所有 Connector 收到的请求 --> <Service name="Catalina"> <Service name="Apache"> 第一个<Service>处理所有直接由 Tomcat 服务器接收的 web 客户请求. 第二个<Service>处理所有由 Apahce 服务器转发过来的 Web 客户请求 . 1>className 指定实现 org.apahce.catalina.Service 接口的类.默认为 org.apahce.catalina.core.StandardService 2>name 定义 Service 的名字 <Connector>元素 由 Connector 接口定义.<Connector>元素代表与客户程序实际交互的给件,它负责接收客户请求,以及向客户返 回响应结果. <!-- 一个“Connector”(连接器)代表一个请求被接收和应答所需要的端点。每个连 接器通过相关的“Container”(容器)处理请求。 默认情况下,一个非 SSL 的 HTTP/1.1 的连接器被绑定在端口 8080。你也可以通过 根据后面的使用说明并取消第二个连接器入口的注释,在端口 8443 上建立一个 SSL HTTP/1.1 的连接器。开放 SSL 支持需要下面几步(参见 Tomcat 5 文档中怎样 配置 SSL 的说明以取得更多的详细信息): * 如果你的 JDK 是 1.3 或 1.3 以前的版本,下载安装 JSSE 1.0.2 或以后版本,并放 置 JAR 文件到“$JAVA_HOME/jre/lib/ext”目录下。 * 带一个“changeit”的口令值执行: %JAVA_HOME%binkeytool -genkey -alias tomcat -keyalg RSA (Windows) $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA (UNIX) 来生成它自己的证书私钥。 默认情况下,当一个 web 应用程序调用请求时,DNS 查询是可行的。这将对性能造 成一些不利的影响,因此,你可以将“enableLookups”设置为“false”来关闭 DNS 查询。当 DNS 查询被关闭时,request.getRemoteHost()将返回包含远程客户 IP 地 址的字符串。 --> <!-- Coyote HTTP/1.1 Connector className : 该 Connector 的实现类是 org.apache.coyote.tomcat4.CoyoteConnector port : 在端口号 8080 处侦听来自客户 browser 的 HTTP1.1 请求.如果把 8080 改成 80,则只要输入 http://localhost/即可 protocol:设定 Http 协议,默认值为 HTTP/1.1 minSpareThreads: 该 Connector 先创建 5 个线程等待客户请求,每个请求由一个线程负责 maxSpareThread:设定在监听端口的线程的最大数目,这个值也决定了服务器可以同时响应客户请求的最大数目. 默认值为 200 acceptCount : 当现有线程已经达到最大数 75 时,为客户请求排队.当队列中请求数超过 100 时,后来的请 求返回 Connection refused 错误
  • 5. redirectport : 当客户请求是 https 时,把该请求转发到端口 8443 去 enableLookups:如果设为 true,表示支持域名解析,可以把 IP 地址解析为主机名.WEB 应用中调用 request.getRemoteHost 方法返回客户机主机名.默认值为 true connectionTimeout:定义建立客户连接超时的时间.如果为-1,表示不限制建立客户连接的时间 其它属性略 --> <Connector port="8080" maxThread="50" minSpareThreads="25"maxSpareThread="75" enableLookups="false" redirectPort="8443"acceptCount="100" debug="0" cdisableUploadTimeout="true" /> <Connection port="8009" enableLookups="false" redirectPort="8443" debug="0" protocol="AJP/1.3" /> 第一个 Connector 元素定义了一个 HTTP Connector,它通过 8080 端口接收 HTTP 请求;第二个 Connector 元 素定义了一个 JD Connector,它通过 8009 端口接收由其它服务器转发过来的请求. <Engine>元素 每个 Service 元素只能有一个 Engine 元素.处理在同一个<Service>中所有<Connector>元素接收到的客户请 求.由 org.apahce.catalina.Engine 接口定义. <!-- 一个“Engine”(引擎)代表处理每个请求的入口点(在 Catalina 内)。这个 Tomcat 的标准独立引擎实现分析包含在请求中的 HTTP 头信息,并将请求传送到适当的主机 或虚拟主机上。--> <!-- Engine 用来处理 Connector 收到的 Http 请求 它将匹配请求和自己的虚拟主机,并把请求转交给对应的 Host 来处理 默认虚拟主机是 localhost --> <Engine name="Catalina" defaultHost="localhost" debug="0"> 1>className 指定实现 Engine 接口的类,默认值为 StandardEngine 2>defaultHost 指定处理客户的默认主机名,在<Engine>中的<Host>子元素中必须定义这一主机 3>name 定义 Engine 的名字 在<Engine>可以包含如下元素<Logger>, <Realm>, <Value>, <Host> <Host>元素 它由 Host 接口定义.一个 Engine 元素可以包含多个<Host>元素.每个<Host>的元素定义了一个虚拟主机.它包 含了一个或多个 Web 应用. <!-- 定义默认的虚拟主机 注意:XML 模式确认将不能与 Xerces 2.2 同工作。 --> <!-- 虚拟主机 localhost appBase :指定虚拟主机的目录,可以指定绝对目录,也可以指定相对于<CATALINA_HOME>的相对目 录.如果没有此项,默认为<CATALINA_HOME>/webapps.它将匹配请求和自己的 Context 的路径,并把请求转 交给对应的 Context 来处理 autoDeploy:如果此项设为 true,表示 Tomcat 服务处于运行状态时,能够监测 appBase 下的文件,如 果有新有 web 应用加入进来,会自运发布这个 WEB 应用 unpackWARs:如果此项设置为 true,表示把 WEB 应用的 WAR 文件先展开为开放目录结构后再运行. 如果设为 false 将直接运行为 WAR 文件
  • 6. alias:指定主机别名,可以指定多个别名 deployOnStartup:如果此项设为 true,表示 Tomcat 服务器启动时会自动发布 appBase 目录下所有 的 Web 应用.如果 Web 应用中的 server.xml 没有相应的<Context>元素,将采用 Tomcat 默认的 Context --> <Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true"> 在<Host>元素中可以包含如下子元素 <Logger>, <Realm>, <Value>, <Context> <Context>元素 它由 Context 接口定义.是使用最频繁的元素.每个<Context 元素代表了运行在虚拟主机上的单个 Web 应用.一 个<Host>可以包含多个<Context>元素.每个 web 应用有唯一 的一个相对应的 Context 代表 web 应用自身.servlet 容器为第一个 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 path="" docBase="mycontext" debug="0"/> Tomcat Server 处理一个 http 请求的过程 假设来自客户的请求为: http://localhost:8080/wsota/wsota_index.jsp 1) 请求被发送到本机端口 8080,被在那里侦听的 Coyote HTTP/1.1 Connector 获得 2) Connector 把该请求交给它所在的 Service 的 Engine 来处理,并等待来自 Engine 的回应 3) Engine 获得请求 localhost/wsota/wsota_index.jsp,匹配它所拥有的所有虚拟主机 Host 4) Engine 匹配到名为 localhost 的 Host(即使匹配不到也把请求交给该 Host 处理,因为该 Host 被定义为该 Engine 的默认主机) 5) localhost Host 获得请求/wsota/wsota_index.jsp,匹配它所拥有的所有 Context 6) Host 匹配到路径为/wsota 的 Context(如果匹配不到就把该请求交给路径名为""的 Context 去处理) 7) path="/wsota"的 Context 获得请求/wsota_index.jsp,在它的 mapping table 中寻找对应的 servlet 8) Context 匹配到 URL PATTERN 为*.jsp 的 servlet,对应于 JspServlet 类 9) 构造 HttpServletRequest 对象和 HttpServletResponse 对象,作为参数调用 JspServlet 的 doGet 或 doPost 方法 10)Context 把执行完了之后的 HttpServletResponse 对象返回给 Host 11)Host 把 HttpServletResponse 对象返回给 Engine 12)Engine 把 HttpServletResponse 对象返回给 Connector 13)Connector 把 HttpServletResponse 对象返回给客户 browser