您的位置:首页 > 运维架构 > Tomcat

tomcat学习(二) tomcat配置文件server.xml详解

2015-04-24 17:26 573 查看
1.本地service.xml 目录:D:\Program Files\tomcat\apache-tomcat-7.0.59\conf\server.xml

<?xml version='1.0' encoding='utf-8'?>

<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

<GlobalNamingResources>

<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 name="Catalina">

<!-- 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 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 a SSL HTTP/1.1 Connector on port 8443
This connector uses the BIO 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.Http11Protocol"
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" />

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

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


2.配置详解





3.<Server>元素

它代表整个容器,是Tomcat实例的顶层元素.由org.apache.catalina.Server接口来定义.它包含一个<Service>元素.并且它不能做为任何元素的子元素.
< 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监听端口的字符串.该属性必须设置

4.<Serveice>元素

该元素由org.apache.catalina.Service接口定义,它包含一个<Engine>元素,以及一个或多个<Connector>,这些Connector元素共享用同一个Engine元素
< 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的名字

5.<Engine>元素

每个Service元素只能有一个Engine元素.元素处理在同一个<Service>中所有<Connector>元素接收到的客

户请求.由org.apahce.catalina.Engine接口定义.
< Engine name ="Catalina" defaultHost ="localhost" debug ="0" >
1>className指定实现Engine接口的类,默认值为StandardEngine

2>defaultHost指定处理客户的默认主机名,在<Engine>中的<Host>子元素中必须定义这一主机

3>name定义Engine的名字在<Engine>可以包含如下元素<Logger>, <Realm>, <Value>, <Host>

6.<Host>元素

它由Host接口定义.一个Engine元素可以包含多个<Host>元素.每个<Host>的元素定义了一个虚拟主机.它包含了一个或多个Web应用.
< Host name ="localhost" debug ="0" appBase ="webapps" unpackWARs ="true" autoDeploy ="true" >


1>className指定实现Host接口的类.默认值为StandardHost

2>appBase指定虚拟主机的目录,可以指定绝对目录,也可以指定相对于<CATALINA_HOME>的相对目录.如果没有此项,

默认为<CATALINA_HOME>/webapps

3>autoDeploy如果此项设为true,表示Tomcat服务处于运行状态时,能够监测appBase下的文件,如果有新有web应用加入进来,会自运发布这个WEB应用

4>unpackWARs如果此项设置为true,表示把WEB应用的WAR文件先展开为开放目录结构后再运行.如果设为false将直接运行为WAR文件

5>alias指定主机别名,可以指定多个别名

6>deployOnStartup如果此项设为true,表示Tomcat服务器启动时会自动发布appBase目录下所有的Web应用

如果Web应用中的server.xml没有相应的<Context>元素,将采用Tomcat默认的Context

7>name定义虚拟主机的名字在<Host>元素中可以包含如下子元素<Logger>, <Realm>, <Value>, <Context>

7.<Context>元素

它由Context接口定义.是使用最频繁的元素.每个<Context元素代表了运行在虚拟主机上的单个Web应用.一个<Host>可以包含多个<Context>元素.

每个web应用有唯一的一个相对应的Context代表web应用自身.servlet容器为第一个web应用创建一个ServletContext对象.
< Context path ="/sample" docBase ="sample" debug ="0" reloadbale ="true" >


1>className指定实现Context的类,默认为StandardContext类

2>path指定访问Web应用的URL入口,注意/myweb,而不是myweb了事

3>reloadable如果这个属性设为true, Tomcat服务器在运行状态下会监视在WEB-INF/classes和Web-INF/lib目录CLASS文件的改运.

如果监视到有class文件被更新,服务器自重新加载Web应用

3>cookies指定是否通过Cookies来支持Session,默认值为true

4>useNaming指定是否支持JNDI,默认值为了true在<Context>元素中可以包含如下元素<Logger>, <Realm>, <Resource>, <ResourceParams>

8.<Connector>元素

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

< Connector port ="8080" maxThread ="50" minSpareThreads ="25" maxSpareThread ="75" enableLookups ="false" redirectPort ="8443" 
acceptCount ="100" debug ="0" connectionTimeout ="20000" disableUploadTimeout ="true" />
< Connection port ="8009" enableLookups ="false" redirectPort ="8443" debug ="0" protocol ="AJP/1.3" />


第一个Connector元素定义了一个HTTP Connector,它通过8080端口接收HTTP请求;第二个Connector元素定义了一个JD Connector,它通过8009端口接收由其它服务器转发过来的请求.

Connector元素共用属性

1>className指定实现Connector接口的类

2>enableLookups如果设为true,表示支持域名解析,可以把IP地址解析为主机名.WEB应用中调用request.getRemoteHost方法,

返回客户机主机名.默认值为true

3>redirectPort指定转发端口.如果当前端口只支持non-SSL请求,在需要安全通信的场命,将把客户请求转发至SSL的redirectPort端口HttpConnector元素的属性

1>className实现Connector的类

2>port设定Tcp/IP端口,默认值为8080,如果把8080改成80,则只要输入http://localhost 即可因为TCP/IP的默认端口是80

3>address如果服务器有二个以上ip地址,此属性可以设定端口监听的ip地址.默认情况下,端口会监听服务器上所有的ip地址

4>bufferSize设定由端口创建的输入流的缓存大小.默认值为2048byte

5>protocol设定Http协议,默认值为HTTP/1.1

6>maxThreads设定在监听端口的线程的最大数目,这个值也决定了服务器可以同时响应客户请求的最大数目.默认值为200

7>acceptCount设定在监听端口队列的最大客户请求数量,默认值为10.如果队列已满,客户必须等待.

8>connectionTimeout定义建立客户连接超时的时间.如果为-1,表示不限制建立客户连接的时间

JkConnector的属性

1>className实现Connector的类

2>port设定AJP端口号

3>protocol必须设定为AJP/1.3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: