tomcat7 configuration file server.xml parsing

  • 2020-06-15 10:32:42
  • OfStack

The server.xml file of tomcat7 is explained here. It is easy to understand what Digester does when analyzing the source code for launching.


<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
 <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
 <Listener className="org.apache.catalina.security.SecurityListener" />
 <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">
  <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
    maxThreads="150" minSpareThreads="4"/>

  <Connector port="8080" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" />

  <Connector executor="tomcatThreadPool"
        port="8080" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" />

  <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
        maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
        clientAuth="false" sslProtocol="TLS" />

  <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

  <Engine name="Catalina" defaultHost="localhost">

   <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

   <Realm className="org.apache.catalina.realm.LockOutRealm">
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
        resourceName="UserDatabase"/>
   </Realm>

   <Host name="localhost" appBase="webapps"
      unpackWARs="true" autoDeploy="true">

    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />

    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
        prefix="localhost_access_log." suffix=".txt"
        pattern="%h %l %u %t &quot;%r&quot; %s %b" />
   </Host>
  </Engine>
 </Service>
</Server>

Server

In tomcat, Server represents 1 instance of tomcat, so there will only be 1 instance of Server, and it also appears as a top-level element in the configuration file. The code is as follows:


<Server port="8005" shutdown="SHUTDOWN">
 . 
</Server>
port, listen on the port of the shutdown command, -1 means disable the shutdown command. shutdown, turn off the tomcat command.

Listener

A listener that listens for certain events to happen.


<Listener className="org.apache.catalina.startup.VersionLoggerListener" />

VersionLoggerListener, at startup prints a log of tomcat, java, OS information.


<Listener className="org.apache.catalina.security.SecurityListener" />

SecurityListener, when tomcat is started, do some safety checks.


<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

AprLifecycleListener, used to listen to Apache server related.


<Listener className="org.apache.catalina.core.JasperListener" />

JasperListener, Jasper 2 JSP engine, which is responsible for recompiling the updated jsp.


<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />

JreMemoryLeakPreventionListener, listener to prevent memory overflow.


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

GlobalResourcesLifecycleListener, initializes the global JNDI resource defined under element GlobalNamingResources


<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

ThreadLocalLeakPreventionListener to prevent ThreadLocal from overflowing the listener.

GlobalNamingResources

GlobalNamingResources defines the global JNDI resource for Server. Can be referenced for all engine applications.


<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>

An JNDI, named UserDatabase, is defined in the configuration file and passed conf/tomcat-users.xml To get 1 database for authorized users is 1 in-memory database.

Service


<Service name="Catalina">
 . 
</Service>

There can be multiple Service under Server and multiple Connector and one Engine under Service. The default Service name here is Catalina, with two Connector below: Http and AJP.

name, Service display name, name must only be 1.

Connector


<Connector port="8080" protocol="HTTP/1.1"
      connectionTimeout="20000"
      redirectPort="8443" />

Above is Connector for handling http requests.

port, port 8080. protocol, Agreement, http agreement connectionTimeout, maximum wait time for response, 20 seconds redirectPort, ssl requests will be redirected to port 8443

<Connector executor="tomcatThreadPool"
      port="8080" protocol="HTTP/1.1"
      connectionTimeout="20000"
      redirectPort="8443" />

Above, use the thread pool to handle http requests.


<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
      maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
      clientAuth="false" sslProtocol="TLS" />

Above processing ssl request, port 8443.


<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Above processing AJP requests, tomcat and apache's http server 1 can be run.

Engine

Engine is the container, one Service contains only one Engine:


<Engine name="Catalina" defaultHost="localhost">
...
</Engine>

Engine can contain one or more Host. Engine maps the hostname or ip in the header information from the http request to the true host.

name, Engine name, need only 1. defaultHost, the default host name

Cluster

Cluster related configuration. tomcat supports clustering of servers, and you can replicate the response and context properties of an entire cluster, or you can deploy 1 war package to all clusters.


<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

Realm


<Server port="8005" shutdown="SHUTDOWN">
 . 
</Server>
0

Realm is a database containing user, password, and role that can be defined in any container. This is certified through an external resource, UserDatabase.

Host


<Server port="8005" shutdown="SHUTDOWN">
 . 
</Server>
1

Host virtual host, defined under Engine, one Engine can have multiple Host, one Host can have multiple Context.

name, the network name of the virtual host, must have a name of host and defaulHost1 like Engine. appBase, the root directory of virtual host application, default is webapps. unpackWARs, war file in webapps directory should be unzipped. autoDeploy. When the value is true, tomcat will periodically check appBase and other directories to deploy new web applications and Context description files.

Value


<Server port="8005" shutdown="SHUTDOWN">
 . 
</Server>
2

Value means valve here and can intercept http requests, which can be defined in any container.

SingleSignOn is single sign-on, AccessLogValve is access log record.


Related articles: