Detailed explanation of server.xml parameters and configuration in tomcat

The Tomcat server is composed of a series of configurable components. Its core component is the Catalina Servlet container, which is the top-level container for all other Tomcat components. Tomcat components can be configured in the <CATALINA_HOME>/conf/server.xml file. Each Tomcat component corresponds to a configuration element in the server.xml file. The following code shows the various Tomcat components in the form of XML. The relationship between: The

      <Server> element
        represents the entire Catalina Servlet container, which is the top-level element of the Tomcat instance. It can contain one or more <Service> elements.

        <Service> elements --- If different ports are deployed for different applications, multiple Services will be copied
        Contains an <Engine> element, and one or more <Connector> elements that share the same <Engine> element. The

        <Connector> element
        represents the component that actually interacts with the client program, it is responsible for receiving client requests, and Returns the response result to the client.

        <Engine> Element ---
        Each <Service> element of a virtual host can contain only one <Engine> element. The <Engine> element handles all <Connector> elements received in the same <Service> Client request.

        <Host> element
        A <Engine> element can contain multiple <Host> elements. Each <Host> element defines a virtual host,

      
        Each <Context> element represents a web application running on a virtual host. A <Host> element can contain multiple <Context> elements.

The Tomcat server is composed of a series of configurable components. Tomcat components can be found in <CATALINA_HOME>\conf\server.xml file for configuration, each Tomcat component corresponds to a configuration element in the server.xml file. Some commonly used elements are introduced below. For more information on server.xml, You can refer to Tomcat's documentation:

          <CATALINA_HOME>/webapps/tomcat-docs/config/index.html



There are three ways to deploy multiple applications with tomcat:

1. Use multiple Context elements in the configuration file. The advantage of this configuration is that these applications share the same connector, which means that the access ports are the same, so they can all be deployed under 80.

There is a requirement that the application supports Context when it is designed, and some links are preceded by a dynamic application name instead of using an absolute path such as "/". The path of the Context element must not end with "/", it can be "" or "/WEB1".



2. Use multiple Service elements in the configuration file. This configuration can solve the situation that the application does not support dynamic application name, and use different ports to access different pages.

However, sometimes this is not very smooth. Since a tomcat JVM only allows one jni class to be loaded once, if your multiple applications load a jni class at the same time, the deployment will fail. In this case, you can take this class out of the project and put it under the lib of the tomcat installation directory as a public one. But it's still a little troublesome~



3. Deploy multiple tomcats. This is generally used for clustering, but you can also use it to deploy multiple applications, as long as the ports are adjusted so that there is no conflict.


The following is a sample server.xml file:

1.     Configure the Server element
The         <Server> element represents the entire Catalina Servler container, which is the top-level element of the Tomcat instance and is defined by the org.apache.catalina.Server interface. The <Server> element can contain one or more <Service> elements, but the <Server> element cannot be a child element of any other element. The <Server> element defined in the sample code is as follows:
         <Server port="8005" shutdown="SHUTDOWN" debug ="0">
          className       : Specifies the class that implements the org.apache.catalina.Server interface. The default value is org.apache.catalina.core.StandardServer.
          port                  : Specifies the port on which the Tomcat server listens for the shutdown command. When the Tomcat service is terminated, The Shutdown command must be issued on the machine where the Tomcat server is located. This property must be set.
         shutdown     : Specifies the string of the shutdown listening port sent to the Tomcat server when the Tomcat server is terminated. This property must be set.


2 .Configure    the Service element
          The <Service> element is defined by the org.apache.catalina.Service interface, which contains an <Engine> element, and one or more <Connector> elements that share an <Engine> element. For example, in the example document Two <Service> elements are configured in
          <Service name="Catalina">
          className        : specifies the class that implements the org.apache.catalina.Service interface, the default value is org.apache.catalina.core.StandardService.
         name                : defines the Service Name.

3.    Configuring Engine Elements
          The <Engine> element is defined by the org.apahe.catalina.Engine interface. Each <Service> element can only contain one <Engine> element. The client request received by the <Connector> element. For example, the <Engine> element configured in the sample server.xml file:
          <Engine name="Catalina" defaultHost="localhost" debug="0">   
          className        : Specifies the class that implements the org.apache.catalina.Engine interface. The default value is org.apache.catalina.core.StandardEngine.
          name                : Defines the name of the Engine.

          The <Engine> element can contain the following sub-elements:
                  <Logger>
                  <Realm>
                  <Valve>
                  <Host>

4.    Configure the Host element
          The <Host> element is defined by the org.apache.catalina.Host interface. An <Engine> element can contain multiple <Host> elements. Each <Host> element defines A virtual host is created, which can contain one or more web applications. For example, the following <Host> element is configured in the sample server.xml:
          <Host name="localhost" debug="0" appBase="webapps" unpackWARs ="true" autoDeploy="true"> 
         className           : Specifies the implementation of org.apache. The class of the catalina.Host interface, the default value is
          org.apache.catalina.core.StandardHost.appBase                : Specify the directory of the virtual host. You can specify an absolute directory or a relative directory relative to <CATALINA_HOME>. If this item is not set, the default value is <CATALINA_HOME>/webapps.
          unpackWARs          : If this item is set to true, it means The WAR file of the web application will be expanded into an open directory structure before running. If set to false, the WAR file will be run directly.
          autoDeploy          : If this item is set to true, it means that when the Tomcat server is running, it can monitor appBase If a new web application is added, the web application will be published automatically.
          alias                   : Specify the alias of the virtual host, and multiple aliases can be specified.
          deployOnStartup      : If this item is set to true, it means that the Tomcat server will be automatically published when it starts. For all web applications in the appBase directory, if the web application does not have a corresponding <Context> element in server.xml, Tomcat's default Context will be used. The default value of deployOnStartup is true.
          name                     : Define the name of the virtual host.}

          In <Host The > element can contain the following child elements:
                  <Logger>
                  <Realm>
                  <Valve>
                  <Context>

5.     Configure Context
          elements Application. A <Host> element can contain multiple <Context> elements. For example, the following <Context> elements are configured in the sample server.xml file:
   <Context path="/sample" docBase="sample" debug= "0" reloadable="true">     
          className : Specifies the class that implements the org.apache.catalina.Context interface. The default value is org.apache.catalina.core.StandardContext.
          path                   : Specifies the URL entry for accessing the web application.
          docBase              : Specify the file path of the web application. You can specify an absolute path or a relative path relative to the appBase property of the Host. If the web application uses an open directory structure, specify the root directory of the web application; if the web application is a WAR file , then specify the path to the WAR file.
          reloadable        : If this property is set to true, the Tomcat server will monitor changes to the CLASS files in the WEB-INF/class and WEB-INF/lib directories while it is running. If it detects that the calss file has been updated, the server will automatically reload the web Application.
          cookies              : Specifies whether to support Session through cookies, the default is true.
          useNaming          : Specifies whether to support JNDI, the default is true.

          The <Context> element can contain the following sub-elements:
                  <Logger>
                  <Realm>
                  <Valve>
                  < Resource>
                  <ResourceParams>

6.     Configure the Connector element
          The <Connector> element is defined by the org.apache.catalina.Connector interface. The <Connector> element represents the component that actually interacts with the client program, it is responsible for receiving the client's request and returning the response to the client Result. For example, two <Connector> elements are configured in the sample server.xml file:
          <Connector prot="8009" enableLookups="false" redirectPort"8443" debug="0" protocol="AJP/1.3"/>           

          The first <Connector> element defines an HTTP Connector that receives HTTP requests through port 8080 ;
          The second <Connector> element defines a JK Connector, which receives client requests forwarded by other HTTP servers (such as Apache servers) through port 8009.

          All <Connector> elements have some common attributes, these attributes are as follows : <Connector <Connector port="8080"
                                    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                                    enableLookups="false" redirectPort="8443" acceptCount="100"
                                    debug="0"     connectionTimeout="20000" 
                                    disableUploadTimeout="true"     /> 


          className                : Specifies the class that implements the org.apache.catalina.Connector interface. The default value is org.apache.catalina.core.StandardConnector.
          enableLookups       : If set to true, it means that domain name resolution is supported, and IP addresses can be resolved to host names. Web The application calls the request.getRemostHost method to return the client's host name. The default value of this property is true.
          redirectPort         : specifies the forwarding port. If the current port only supports non-SSL requests, when secure communication is required, the client request will be forwarded to the The port of the SSL redirectPort.

         The properties of HttpConnector are described as follows:
-------------------------------------- ------------------------
         calssName                : Specify the class that implements the org.apache.catalina.Connector interface, the default value is org.apache.coyote.tomcat5. CoyoteConnector.
          enableLookups       : same as above.
          redirectPort          : same as above.
          prot                         : set TCP/IP port number, the default is 8080.
          address                   : If the server has more than two IP addresses, this property can set the IP address of the port listening. By default, the port will listen to all IP addresses on the server.
         bufferSize             : Set the buffer size of the input stream created by the port, the default value It is 2048byte.
         protocol                 : set the HTTP protocol, the default value is HTTP/1.1.
         maxThreads              : set the maximum number of threads processing client requests, this value also determines the server can respond to the maximum number of client requests at the same time, the default value is 200.
          acceptCount           : Set the maximum number of client requests in the listening port queue, the default value is 10. If the queue is full, the client request will be rejected.
          connectionTimeout      : Define the timeout for establishing a client connection, in milliseconds. If set to - 1, means that the time for establishing a client connection is not limited.

         The properties of JK Connector are as follows:
--------------------------------- -----------------------------
          className : Specify the class that implements the org.apache.catalina.Connector interface, the default value is org.apache .coyote.tomact5.CoyoteCnnector.enableLookups
          : same as above.
          redirectPort : same as above.
          port : set the AJP port number.
          protocol : must be set to AJP/1.3 protocol.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326990043&siteId=291194637