Read the main configuration file of Tomcat server.xml in one article

This file is located in the conf directory under the tomcat 6 installation directory, and the actual content is located in /etc/tomcat6/server.xml.

As the extension of the file shows, this is an xml file, and after opening, you will see the following structure:

    <Server port=”8005″ shutdown=”SHUTDOWN”>

    <Service name=”Catalina”>

    <Executor …… />

    <Connector …… />

    <Connector …… />

    <Engine name=”Catalina” … >

    <Host name=”Weikeyun.cn” … >

    <Context … />

    </Host>

    </Engine>

    </Service>

    </Server>

 

That is, a four-layer structure composed of Server->Service->Engine->Host->Context, from the inner layer to the outer layer are:

Context: Web application, a Context is for a Web application.

Host: The virtual host, for example, www.weikeyun.cn corresponds to one virtual host, and api.weikeyun.cn corresponds to another virtual host. A Host is used to define a virtual host. (The so-called "a virtual host" can be simply understood as "a website")

Engine: A collection of virtual hosts. For example, www.weikeyun.cn and api.weikeyun.cn can form a set of virtual hosts.

Service: A set of Engines, including the definition of the thread pool Executor and the connector Connector.

CONNECTOR CONFIGURATION

A Connector is a port open to the outside world. A simple understanding is the combination of IpAddress:Port that most network service programs encounter. For example, 192.168.0.10:8080 is a port. Of course, the content that can be defined in the Connector is much richer. , that is, many attributes can be added to the XML node of Connector. Here are the commonly used ones:

enableLookups: (default=true) Whether to allow reverse resolution of the visitor's IP address. When your application uses request.getRemoteHost(), if only the IP address is required, it is recommended to disable this option, which can save the time of reverse domain name resolution. ssl certificate application

maxPostSize: (default=2097152 is 2MB) The maximum allowable POST upload data size (unit: bytes). For general websites, such as websites that write comments and articles, the default 2MB is enough, but if the website has The picture and even file upload function need to be determined according to the specific situation.

protocol: the type of connector, tomcat 6 has the following options

org.apache.coyote.http11.Http11Protocol: Abbreviated as "HTTP/1.1", this is the default connector, a guest network connection requires one thread, and the concurrency performance is relatively low.

org.apache.coyote.http11.Http11NioProtocol: NIO connector, a connector composed of non-blocking socket working mode, with good concurrency performance, pure Java implementation.

org.apache.coyote.http11.Http11AprProtocol: APR connector. The so-called APR is the library used by Apache Http Server, the web service program most used by servers on the network. Tomcat is recommended to be used in the production environment. The specific method will be introduced below.

redirectPort: When a user accesses a non-https resource and the resource needs to be accessed by https, tomcat will automatically redirect to the https port. Generally, https uses the TCP port 443, so the value is generally "443".

SSLEnabled: (default=false), set whether the current connector uses secure SSL transmission, if set to "true", the following two properties should be set at the same time: scheme=”https” (default=http) can be set to http or https . secure=”true” (default=false).

adress: The IP address bound to the connector. When a server has multiple IP addresses, you can specify one of them that needs to be bound. By default, if the value of this property is not set, it means binding all IP addresses of the current server.

compressableMimeType: (default=”text/html,text/xml,text/plain”) Specifies the type of resources that require GZIP compression.

compression: (default=off) Whether to enable GZIP compression, the value can be on/off/force. After setting to on, GZIP compression will be enabled for the resource type specified by the compressableMimeType attribute.

connectionTimeout: (default=”60000”) The time the server waits for the first line of Request header to appear after the guest is connected to the network. The unit is milliseconds.

executor: Specifies the name of the thread pool used by the current connector. If specified, other settings for the number of threads, such as maxThreads, are ignored.

maxThreads: (default=200) The maximum number of threads that can be created.

port="80": bind port.

keepAliveTimeout: (default=connectionTimeout), the time for the visitor to maintain the network connection after completing a request.

A simple Connector is defined as follows:

    <Connector port=”80″ protocol=”HTTP/1.1″

    connectionTimeout=”60000″

    redirectPort=”443″ />

EXECUTOR CONFIGURATION

Executor is used to define a shared thread pool. By default, each Connector will generate its own thread pool. If you want multiple Connectors to share a thread pool, you can define a thread pool first, such as:

    <Executor name=”tomcatThreadPool” namePrefix=”catalina-exec-”

    maxThreads=”150″ minSpareThreads=”4″/>

Then modify the above Connector configuration and add the executor attribute. The modified configuration is as follows:

    <Connector executor=”tomcatThreadPool”

    port=”80″ protocol=”HTTP/1.1″

    connectionTimeout=”60000″

    redirectPort=”443″ />

Configuration of HOST

A Host configuration is a virtual host. For example, the following is a simple Host configuration:

    <Host name=”Weikeyun.cn” appBase=”webapps”

    unpackWARs=”true” autoDeploy=”true”>

    <Alias>Weikeyun.cn</Alias>

    <Valve className=”org.apache.catalina.valves.AccessLogValve” directory=”logs”

    prefix=”蔚可云.cn_access_log.” suffix=”.txt” pattern=”common” resolveHosts=”false”/>

    </Host>

The role of each attribute of the Host configuration node:

name: Set the domain name of the virtual host. For example, Weikeyun.cn means the name of the machine. In actual application, you should fill in the specific domain name, such as www.weikeyun.cn or Weikeyun.cn. Of course, if the virtual host is for internal For personnel access, you can also directly fill in the IP address of the server, such as 192.168.1.10.

autoDeploy: Whether to allow automatic deployment, the default value is true, which means that Tomcat will automatically detect the file changes under the appBase directory and automatically apply them to the running Web application.

unpackWARs: Set whether to automatically expand the war archive before running the web application, the default value is true.

appBase: Sets the path to the web application group. As mentioned earlier, a virtual host can be composed of multiple web applications, so the directory pointed to by appBase here should be the directory that is prepared to store this group of web applications, not the directory itself of a specific web application ( even if the virtual host consists of only one web application). The value of the appBase attribute can be a relative path relative to the Tomcat installation directory, or an absolute path. It should be noted that this path must be accessible to Tomcat. Tomcat installed from Arch Linux sources is run by the tomcat user, so After creating a new appBase directory, you can use the chown command to change the owner of the directory.

The following example shows how to create a new virtual host www.weikeyun.cn:

Under the directory /var/lib/tomcat6, you can see the webapps directory created by default when Tomcat is installed. In order to facilitate the management of the virtual host document we are about to create, it is also created in /var/lib/tomcat6:

    $ sudo mkdir dog

Then create the directory ROOT in the dog directory, and then create the file index.html (with any content) in ROOT.

Now change the owner and all groups of the directory to tomcat:

    $ sudo chown -R tomcat:tomcat dog

Then add the following Host node under the Host node of server.xml:

    <Host name=”www.weikeyun.cn” appBase=”/var/lib/tomcat6/dog”>

    </Host>

After restarting the Tomcat service, you can access the newly created virtual host through the address http://www.weikeyun.cn in the browser. Of course, you must first add www.weikeyun in the /etc/hosts file. The parsing records from cn to 127.0.0.1 are as follows:

127.0.0.1 www.weikeyun.cn

Sometimes a virtual host may be bound to multiple domain names at the same time, such as www.weikeyun.cn and Weikeyun.cn, which can be achieved by adding Alias ​​to the Host configuration node, such as:

    <Alias>Weikeyun.cn</Alias>

In addition, <Valve className=… /> in the above example configures the storage location and file name of the visitor's access log.

Configuration of ENGINE

The default Engine nodes are as follows:

    <Engine name=”Catalina” defaultHost=”蔚可云.cn”>

    </Engine>

This should not be described, where defaultHost is used to specify the name of the virtual host selected by Tomcat by default when the visitor does not have a corresponding virtual host.

Guess you like

Origin blog.csdn.net/wecloud1314/article/details/123474105