Detailed explanation of tomcat configuration file server.xml

Tomcat is a core project in the Jakarta project of the Apache Software Foundation, developed jointly by Apache, Sun and some other companies and individuals. Thanks to Sun's involvement and support, the latest Servlet and JSP specifications are always present in Tomcat. Because of its advanced technology, stable performance, and free Tomcat, it is deeply loved by Java enthusiasts and recognized by some software developers, becoming a popular Web application server.


Blog content starting address


where the server.xml file is located

~/Tomcat installation directory/conf/server.xml

server.xml file comments

<!-- Server中的port监听关闭tomcat的请求,shutdown指定向端口发送的命令串-->  
<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="<a href="http://lib.csdn.net/base/javase" class='replace_word' title="Java SE知识库" target='_blank' style='color:#df3434; font-weight:bold;'>Java</a>.lang.Integer" value="30"/>  
     <Resource name="UserDatabase" auth="<a href="http://lib.csdn.net/base/docker" class='replace_word' title="Docker知识库" target='_blank' style='color:#df3434; font-weight:bold;'>Container</a>"  
               type="org.apache.catalina.UserDatabase"  
        description="User database that can be updated and saved">  
     </Resource>  
     <ResourceParams name="UserDatabase">  
       <parameter>  
         <name>factory</name>  
   <!--value与Logger差不多prefix和suffix解释一样,className指定value使用的类名如:org.apache.catalina.values.AccessLogValve类可以记录应用程序的访问信息,directory指定log 文件存放位置,pattern有两值,common方式记录远程主机名或ip地址,用户名,日期,第一行请求的字符串,HTTP响应代码,发送的字节数。 combined方式比common记录更多-->  
         <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>  
       </parameter>  
       <parameter>  
         <name>pathname</name>  
         <value>conf/tomcat-users.xml</value>  
       </parameter>  
     </ResourceParams>  
   </GlobalNamingResources>  

   <Service name="Catalina">  

     <!-- Connector中的port创建服务器端的端口号,此端口监听用户端的请求  
maxThreads最大可以创建请求的线程数  
minSpareThreads服务启动时创建的处理请求的进程数  
enableLookups如果为true,则可以通过调用request.getRemoteHost()进行DNS查询来得到远程客户端的实际主机名,若为false则不进行DNS查询,而是返回其ip地址  
redirectPort指定服务器正在处理http请求时收到一个SSL传输请求后重定向的端口号  
acceptCount指定当处理请求线程都被使用时,可以放入处理队列的数目,超出将不进行处理  
connectionTimeout指定超时的时间数(毫秒)-->  
 <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="150" minSpareThreads="4"/>

     <Connector port="8080"  
                maxThreads="150" minSpareThreads="25" maxSpareThreads="75"  
                enableLookups="false" redirectPort="8443" acceptCount="100"  
                debug="0" connectionTimeout="20000"  
                disableUploadTimeout="true" />  

     <Connector port="8009"  
                enableLookups="false" redirectPort="8443" debug="0"  
                protocol="AJP/1.3" />  
<!--Engine指定缺省的处理请求主机名,需要有一个与host元素的name属性一致-->  
     <Engine name="Catalina" defaultHost="localhost" debug="0">  
       <!--logger中表示日志信息className为指定logger使用的类名此类必须实现 org.apache.catalina.Logger接口prefix指定log文件的前缀,suffix指定后缀,timestamp如果为true 则log文件名中加入时间-->  
       <Logger className="org.apache.catalina.logger.FileLogger"  
               prefix="catalina_log." suffix=".txt"  
               timestamp="true"/>  
    <!--Realm存放用户名密码及role<a href="http://lib.csdn.net/base/mysql" class='replace_word' title="MySQL知识库" target='_blank' style='color:#df3434; font-weight:bold;'>数据库</a>,className指定Realm使用的类名必须实现org.apache.catalina.Realm接口-->  
       <Realm className="org.apache.catalina.realm.UserDatabaseRealm"  
                  debug="0" resourceName="UserDatabase"/>  
        <!--host中name是指定的主机名或ip,appBase应用程序目录,unpackWARs如果为true则会自动解压war文件直接运行否则不解压-->  
   <Host name="192.168.4.247" debug="0" appBase="D:/project/hbgs_dddu/webapps"  
        unpackWARs="true" autoDeploy="true"  
        xmlValidation="false" xmlNamespaceAware="false">  
   <!--logger中表示日志信息className为指定logger使用的类名此类必须实现 org.apache.catalina.Logger接口prefix指定log文件的前缀,suffix指定后缀,timestamp如果为true 则log文件名中加入时间-->  
         <Logger className="org.apache.catalina.logger.FileLogger"  
                  directory="logs"   prefix="localhost_log.zx" suffix=".txt"  
             timestamp="true"/>  
   <!--Context一个web应用程序通常为war文件,关于war的具体信息见servlet规范,docBase应用程序的路径或者war 文件的存放路径,path表示此web程序的url前缀,reloadable如果为true,Tomcat会自动检测应用程序的变化,自动装载新的应用程序,那么改变代码将不用再次重新启动tomcat-->  
   <Context path="" docBase="D:/project/hbgs_dddu/webapps" debug="0" reloadable="true"/>  
   </Host>  
     </Engine>  
   </Service>  
</Server>  

The meaning of individual nodes in the file and their associated properties

Server element:

is the root element of the entire configuration file. Represents the entire Catalina container.

Attributes:

className: The class name that implements the org.apache.catalina.Server interface. The standard implementation class is the org.apache.catalina.core.StandardServer class.

Port: The port number on which to listen for commands to shut down the Tomcat server.

Shutdown: The command sent to the port to shut down the Tomcat server.

Such as:

<Serverport=”8005” shutdown=”SHUTDOWN”>

Connector element

The connector is responsible for receiving the client's request and returning the response message to the client.

HTTP connector:

Attributes:

protocol: The value must be HTTP1.1, or AJP/1.3 if the AJP handler is used.

proxyName: If this connector is being used in a proxy configuration, specify this property, returned in request.getServerName().

redirectPort: If the connector does not support SSL requests, if an SSL request is received, the Catalina container will automatically redirect the specified port number for processing.

scheme: Set the name of the protocol, returned in request.getScheme(), the SSL connector is set to "https", and the default is "http".

secure: It can be set to true on SSL connectors, default is false.
URIEncoding: The character encoding used to decode URLs, if not specified the default is ISO-8859-1.

acceptCount: The maximum number of requests queued in the queue when all possible processing threads are in use. When the queue is full, any received requests will be rejected, the default value is 10.

bufferSize: Set the size of the input stream buffer created by the connector, in bytes. By default, the buffer size is 2048 bytes.

compressableMimeType : List of MIMEs, comma separated by default. Defaults are text/html, text/xml, text/plain.

compression: Specifies whether to compress the response data. off: means to prohibit compression, on: means to allow compression (text will be compressed), force: means to compress in all cases, the default value is off.

connectionTimeout: Set the timeout value for the connection, in milliseconds. The default value is 60000=60 seconds.

maxHttpHeaderSize : The maximum size of HTTP request and response headers, in bytes, the default is 4096 bytes.

maxKeepAliveRequest: The maximum number of pipelines sent by the client before the server shuts down. The default value is 100.

maxSpareThreads: The maximum number of idle threads allowed, the default value is 50.

minSpareThreads: Set the number of threads to be created when the connector is started for the first time, to ensure that at least this many idle threads are available. The default value is 4.

port: The TCP port number on which the server socket is listening, the default value is 8080 (required).
socketBuffer: Set the size of the Socket output buffer (in bytes), -1 means disable buffering, and the default value is 9000 bytes.

Such as:

<Connector 
port="8080" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" 
redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" />

AJP connector

Used to integrate Apache with Tomcat. When Apache receives a request for dynamic content, it sends the request to the AJP connector component listening on this port number through the port number specified in the configuration.

Attributes:

backlog: The maximum number of requests queued in the queue when all possible request processing threads are in use. Defaults to 10, when the queue is full, any request will be rejected.

maxSpareThread: The maximum number of idle threads allowed, the default value is 50.

maxThread: The maximum number of threads, the default value is 200.

minSpareThreads: Set the number of threads created when the connector is first started, to ensure that at least so many idle threads are available, the default value is 4.

port: The TCP port number of the server socket, the default value is 8089 (required).

topNoDelay: When true, performance can be improved, the default value is true.

soTimeout: timeout value.
Such as:

<!—Define an AJP1.3 Connector on port 8089-->
<Connector port=”8089” enableLookups=”false” redirectPort=”8443” protocol=”AJP/1.3” />

Engine element

Handle all requests for a specific Service. Each Service can only contain one Engine element, which is responsible for receiving and processing requests received by all connectors of this Service, sending responses back to the connection, and finally displaying them on the client. At least one element must have at least one attribute whose name matches the name specified by defaultHost.

Attributes:

className: Implements the org.apache.catalina.Engine interface. The default implementation class is the org.apache.catalina.core.StandardEngine class.

defaultHost: The default host name, the value must match the name value.这里写代码片

name: Specifies the logical name of the Engine (required).

jvmRoute: The identifier used in load balancing, which must be unique.

Such as:

<Engine name=”Cataline” defaultHost=”localhst”>

 Host element:

Represents a virtual host that handles all requests for a specific virtual host

Properties:
appBase: Set the base directory of the application, either an absolute path or a path name relative to %CATALINA_HOME%.

autoDeploy: Indicates whether to deploy automatically when Tomcat is running, if a new WEB program is added to the directory specified by appBase, the default value is true.

className: The class that implements the org.apache.catalina.Host interface. The standard implementation class is the org.apache.catalina.core.StandardHost class.

deployOnStartup : Whether to automatically deploy all WEB applications in the directory specified by the appBase attribute when Tomcat starts, the default value is true.

name: The network name of the virtual host (required).

Additional properties supported by the standard Host implementation class org.apahce.catalina.core.StandardHost:

deployXML: false will not parse the context.xml inside the WEB application, the default value is true

unPackWARs: The virtual host specifies the path name of the directory used for temporary reading and writing. If not set, Tomcat will provide a suitable directory under the %CATALINA_HOME%/work directory.

Such as:

<Host name=”localhst” appBase=”webapps” unpackWARs=”true” autoDeploy=”true” xmlValidation=”false” xmlNamespaceAware=”false”>

Configure virtual host:

<Host name=”xxx” appBase=”c:/test”>
    <Contentpath=”” docBase=”e:/abe”/>
</Host>

context element:

A WEB application handles all requests of the current WEB application, and each Context must use a unique context path.

Attributes:
className: The class that implements the org.apache.catalina.Context interface, the standard implementation class is the org.apache.catalina.core.StandardContext class.

cookies: Whether to apply cookies to Session, the default value is true.

crossContext: Whether to allow cross-domain access, when true, calling the ServletContext.getContext() method in the program will return a request scheduler for other web programs on the virtual host. The default value is false, and the return value of getContext() for adjusting the path is null.

docBase: Absolute path or relative path relative to Host's appBase property.

privileged: true to allow web applications to use the container's servlets.

path: Specifies the context path. Within a virtual host, the context path must be unique.

reloadable: true, when Tomcat is running, if there are changes in the WEB-INF/classes and WEB-INF/lib directories, Tomcat will automatically reload the WEB application. Although it is convenient, the overhead is also high. The default value is false. We can open it during project development and close it after the project is released.

cacheMaxSize: The maximum value of static resource cache, in KB, the default value is 10240KB.

cachingAllowed: Whether to allow static resource caching, the default is true.

caseSensitive: The default is true, the resource file name is case sensitive, if false is case insensitive.

unpackWAR: The default is true, which automatically decompresses the war package.

workDir: Specifies the directory path name for temporary read and write for the servlet inside the WEB application. If not set, Tomcat will provide a suitable directory under the %CATALINA_HOME%/work directory.

Such as:

<Content path=/abcdocBase=”d:/xyzreloadable=”true” />

server.xml file download address

Chinese commented server.xml file

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325949789&siteId=291194637