Tomcat中server.xml配置介绍

<Server port="8005" shutdown="SHUTDOWN" debug="0">  
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"

            debug="0"/>

<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"

            debug="0"/>

  <GlobalNamingResources>

<Environment name="simpleValue" type="java.lang.Integer" value="30"/>

    <Resource name="UserDatabase" auth="Container"

              type="org.apache.catalina.UserDatabase"

       description="User database that can be updated and saved">

    </Resource>

    <ResourceParams name="UserDatabase">

      <parameter>

        <name>factory</name>

        <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>

      </parameter>

      <parameter>

        <name>pathname</name>

        <value>conf/tomcat-users.xml</value>

      </parameter>

    </ResourceParams>

  </GlobalNamingResources>

  <Service name="Tomcat-Standalone">

    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"

port="8080"               minProcessors="5" maxProcessors="75"

               enableLookups="true" redirectPort="8443"

               acceptCount="100" debug="0" connectionTimeout="20000"

               useURIValidationHack="false" disableUploadTimeout="true" />

    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"

               port="8009" minProcessors="5" maxProcessors="75"

               enableLookups="true" redirectPort="8443"

               acceptCount="10" debug="0" connectionTimeout="20000"

               useURIValidationHack="false"

               protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>

<Engine name="Standalone" defaultHost="localhost" debug="0">

<!--

<Valve className="org.apache.catalina.valves.RequestDumperValve"/>

-->

      <Logger className="org.apache.catalina.logger.FileLogger"

              prefix="catalina_log." suffix=".txt"

              timestamp="true"/>

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

                 debug="0" resourceName="UserDatabase"/>

      <Host name="localhost" debug="0" appBase="webapps"

       unpackWARs="true" autoDeploy="true">

        <Logger className="org.apache.catalina.logger.FileLogger"

                 directory="logs"  prefix="localhost_log." suffix=".txt"

               timestamp="true"/>

<Context path="/gdqy" reloadable="true" docBase="D:/gdqy/ept" debug="0"

crossContext="true"/>

      </Host>

</Engine>

  </Service>

</Server>

1server port:指定一个端口,这个端口负责监听关闭tomcat的请求

2shut down:指定向端口发送的命令字符串

3service name:指定service的名字

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

port 指定服务器端要创建的端口号,并在这个断口监听来自客户端的请求

minProcessors:服务器启动时创建的处理请求的线程数

maxProcessors:最大可以创建的处理请求的线程数

enableLookups:如果为true,则可以通过调用request.getRemoteHost()进行DNS查询来得到远程客户端的实际主机名,若为false则不进行DNS查询,而是返回其ip地址

redirectPort:指定服务器正在处理http请求时收到了一个SSL传输请求后重定向的端口号

acceptCount 指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理

connectionTimeout 指定超时的时间数(以毫秒为单位)
5
Engine(表示指定service中的请求处理机,接收和处理来自Connector的请求)

defaultHost:指定缺省的处理请求的主机名,它至少与其中的一个host元素的name属性值是一样的
6
Context(表示一个web应用程序,通常为WAR文件,关于WAR的具体信息见servlet规范) docBase 应用程序的路径或者是WAR文件存放的路径

path:表示此web应用程序的url的前缀,这样请求的urlhttp://localhost:8080/path/****

reloadable:这个属性非常重要,如果为true,则tomcat会自动检测应用程序的/WEB-INF/lib /WEB-INF/classes目录的变化,自动装载新的应用程序,我们可以在不重起tomcat的情况下改变应用程序

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

name:指定主机名

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

unpackWARs:如果为true,则tomcat会自动将WAR文件解压,否则不解压,直接从WAR文件中运行应用程序

8Logger(表示日志,调试和错误信息)

className 指定logger使用的类名,此类必须实现org.apache.catalina.Logger 接口

prefix:指定log文件的前缀

suffix:指定log文件的后缀

timestamp:如果为true,则log文件名中要加入时间,如下例:localhost_log.2001-10-04.txt
9
Realm(表示存放用户名,密码及role的数据库)

className:指定Realm使用的类名,此类必须实现org.apache.catalina.Realm接口

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

className:指定Valve使用的类名,如用org.apache.catalina.valves.AccessLogValve类可以记录应用程序的访问信息

11
directory:指定log文件存放的位置

pattern 有两个值,common方式记录远程主机名或ip地址,用户名,日期,第一行请求的字符串,HTTP响应代码,发送的字节数。combined方式比common方式记录的值更多。

另附tomcat5中server.xml配置

<!-- Example Server Configuration File -->
<!-- Tomcat服务器配置示例文件 -->

<!-- Note that component elements are nested corresponding to their
      parent-child relationships with each other -->
<!-- 注意,这些组件的构成是根据相互之间的父子关系进行嵌套的。-->

<!-- A "Server" is a singleton element that represents the entire JVM,
      which may contain one or more "Service" instances. The Server
      listens for a shutdown command on the indicated port.

      Note: A "Server" is not itself a "Container", so you may not
      define subcomponents such as "Valves" or "Loggers" at this level.
-->
<!-- 一个“Server”是一个提供完整的JVM的独立组件,它可以包含一个或多个
      “Service”实例。服务器在指定的端口上监听shutdown命令。
    
      注意:一个“Server”自身不是一个“Container”(容器),因此在这里你
      不可以定义诸如“Valves”或者“Loggers”子组件
-->

<Server port="8005" shutdown="SHUTDOWN" debug="0">


   <!-- Comment these entries out to disable JMX MBeans support -->
   <!-- 这些指令组件关闭JMX MBeans支持 -->

   <!-- You may also configure custom components (e.g. Valves/Realms) by
        including your own mbean-descriptor file(s), and setting the
        "descriptors" attribute to point to a ';' seperated list of paths
        (in the ClassLoader sense) of files to add to the default list.
        e.g. descriptors="/com/myfirm/mypackage/mbean-descriptor.xml"
   -->
   <!-- 你也可以通过包含你自己的mbean描述文件配置自定义的组件,然后设置
        “descriptors”属性为以“;”为分隔的文件名列表严将它添加到默认列表
        中,例如:descriptors="/com/myfirm/mypackage/mbean-descriptor.xml"。
-->
      
   <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
             debug="0"/>
   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
             debug="0"/>

   <!-- Global JNDI resources -->
   <!-- 全局JNDI资源 -->
   <GlobalNamingResources>

     <!-- Test entry for demonstration purposes -->
     <!-- 出于示例目的的测试入口 -->
     <Environment name="simpleValue" type="java.lang.Integer" value="30"/>

     <!-- Editable user database that can also be used by
          UserDatabaseRealm to authenticate users -->
     <!-- 可编辑的,用来通过UserDatabaseRealm认证用户的用户数据库 -->
   
     <Resource name="UserDatabase" auth="Container"
               type="org.apache.catalina.UserDatabase"
        description="User database that can be updated and saved">
     </Resource>
     <ResourceParams name="UserDatabase">
       <parameter>
         <name>factory</name>
         <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
       </parameter>
       <parameter>
         <name>pathname</name>
         <value>conf/tomcat-users.xml</value>
       </parameter>
     </ResourceParams>

   </GlobalNamingResources>

   <!-- A "Service" is a collection of one or more "Connectors" that share
        a single "Container" (and therefore the web applications visible
        within that Container). Normally, that Container is an "Engine",
        but this is not required.

        Note: A "Service" is not itself a "Container", so you may not
        define subcomponents such as "Valves" or "Loggers" at this level.
    -->
   <!-- 一个“Service”是一个或多个共用一个单独“Container”(容器)的“Connectors”
        组合(因此,应用程序在容器中可见)。通常,这个容器是一个“Engine”
        (引擎),但这不是必须的。
      
        注意:一个“Service”自身不是一个容器,因此,在这个级别上你不可定义
        诸如“Valves”或“Loggers”子组件。
   -->

posted on 2008-12-23 11:21 丁克设计 阅读(555) 评论(0)  编辑  收藏 所属分类: Tomcat 技术文档


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

留言簿(6)

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜