Details of each node in the Server.xml file in Tomcat

Source: Internet
Author: User
Tags first row java web server port arch linux
Details of each node in the Server.xml file in Tomcat

Because Tomcat is based on Java, it actually has a similar configuration in various Linux distributions, but I've seen fewer articles in the Arch Linux environment to build tomcat, so do it in the Arch Linux practice and come to this. This article assumes that you do not know much about Tomcat, the main text will be in the configuration of Tomcat. 1. Install Java JDK

In the Arch Linux Extra source has JDK7-OPENJDK and openjdk6, can directly use Pacman installation, as to choose which one can depending on the specific situation. I installed the OpenJDK 7:

$ sudo pacman-s jdk7-openjdk
2. Install Tomcat

Similarly, the extra source has Tomcat version 5, 6, 7, depending on the circumstances, I have installed Tomcat 6.

$ sudo pacman-s tomcat6

By default, the Tomcat 6 installation path is/USR/SHARE/TOMCAT6, which lists the role of the primary directory (the arrows indicate the actual location of the directory link):

1./USR/SHARE/TOMCAT6: The program home directory, which is also the location that the variable $CATALINA _home points to, and in the case of a single Tomcat instance, is also the location that the variable $CATALINA _base points to.

2.conf->/etc/tomcat6: Configuration file directory.

3.lib->/usr/share/java/tomcat6: Shares the jar package directory, which is both used by Tomcat and referenced by the Web application.

4.logs->/var/log/tomcat6: Log directory is helpful for finding errors and viewing access records.

5.webapps->/var/lib/tomcat6/webapps: The Default Web application directory, Tomcat 6 brings up several sample programs, as described below.

You can now try to start the Tomcat service:

$ sudo/etc/rc.d/tomcat Start

Depending on the Java runtime installed, there may be an error at startup, check the value of the Tomcat_java_home variable in the startup script configuration file/etc/conf.d/tomcat6, and in my installation Java runtime should be in/opt/java (with $ wh Ich java can be seen), so will:

TOMCAT_JAVA_HOME=/USR/LIB/JVM/JAVA-7-OPENJDK change to the following: Tomcat_java_home=/opt/java

Restart the Tomcat service:

$ sudo/etc/rc.d/tomcat6 Restart

Generally, there should be no problem, open any browser and type in the Address bar "Http://localhost:8080″, if you see Tomcat cat that means that the service has been installed properly and can function properly." 3. Know WebApps catalogue

This directory is located in the TOMCAT6 installation directory, the actual content is located in/var/lib/tomcat6/webapps. Each directory in the WebApps directory corresponds to a Web application, such as the access address of the Docs directory is Http://localhost:8080/docs, and the access address of the manager directory is http://localhost:8080/ Manager, where the more specific is the root directory, the corresponding access address is exactly the root directory of the site, that is, http://localhost:8080/.

The sample program that comes with Tomcat can be accessed individually, where the manager and Host-manager two applications that require logon authentication to access, and the way to increase the number of logged-in users is to edit the configuration files under the Tomcat installation directory conf/ Tomcat-users.xml (actually also a file/etc/tomcat6/tomcat-users.xml), add the following lines:

<role rolename= "Manager-gui"/> <role rolename= "admin-script"/> <role "rolename="
/ >
<user username= "Tomcat" password= "Tomcat" roles= "Manager-gui,admin-script,admin-gui"/>

Then restart the Tomcat service, which allows you to log in with the username Tomcat and password tomcat and access the manager and Host-manager two applications.

Each Java WEB application has the following directory structure:

/index.html the resources that visitors directly access, such as static pictures and CSS style sheets.

/web-inf/A resource that visitors cannot access directly.

/web-inf/classes the Java source code compiled class file for the application.

/web-inf/web.xml The application's configuration file.

/web-inf/lib the package referenced by the application.

Of course not all are necessary, you can even create a directory, such as "Hello", and then only create a index.html file (content casually), that can be accessed through the http://localhost:8080/hello/index.html. (This is not a Web application, of course, this method is for testing only)

The following uses Apache Maven to create a simplest web application that creates the skeleton of a Web application in the user directory:

$ MVN archetype:generate

In the interactive interface,

Choose a number or Apply filter: Enter 174, that is, create a Maven-archetype-webapp type item. Choose Version: Enter 5, that is, Release 1.0. Define value for property ' groupId ': Enter Org.test. Define value for property ' Artifactid ': input demo. Define value for property ' version ': Enter 1.0. Define value for property ' package ': Input Org.test.demo Confirm Properties configuration: Direct return

The above involves MAVEN knowledge that is not covered in this article, and if you are unfamiliar with the free Chinese E-book "Maven in Action", incidentally, Maven is one of the most common tools for building and managing Java projects.

You should now see a directory named Demo that you can use when you go into the Maven package project:

$ CD Demo
 
$ MVN Package

The result of the package is the file./target/demo.war, copy this file to the WebApps directory:

$ sudo cp target/demo.war/var/lib/tomcat6/webapps/

Because the site that the Tomcat creates by default automatically deploys the application, the file that you just copied to the WebApps directory Demo.war is automatically decompressed, and the view WebApps directory should find a directory with a demo name, and you can now try to access http:/in the browser /localhost:8080/demo, you should see "Hello world!." This is the result of the run of the WEB application that you just created with Maven.

It is important to note that the war file that is formed after the Java Web application is packaged is not necessarily uncompressed to run, as will be described in the configuration in the next section. 4. Understand Tomcat's main profile server.xml

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 file's extension shows, this is an XML-formatted file, and you will see the following structure when you open it:

<server port= "8005" shutdown= "shutdown" >
    <service name= "Catalina" >
        <executor .../>
        <connector .../>
        <connector .../>
        <engine name= "Catalina" ... >
            

That is, a four-storey structure composed of server->service->engine->host->context, from the layer to the outer layers are:

1.Context: A Web application, a context that is for a Web application.

2.Host: A virtual host, such as a www.dog.com corresponding to a virtual host, api.dog.com for another virtual host. A host is used to define a virtual host. (The so-called "one virtual host" can be simply understood as "a Web site")

3.Engine: A set of virtual hosts. For example, www.dog.com and api.dog.com can form a set of virtual hosts.

4.Service: A set of Engine, including the definition of thread pool Executor and connector Connector. Configuration of CONNECTOR

A Connector is a port open to the outside, simple understanding is most of the network Service program will encounter a combination of ipaddress:port, such as 192.168.0.10:8080 is a port, of course, in Connector The content that can be defined is much richer, that is, Connector this XML node can add many attributes. Here are some common examples:

Enablelookups: (default=true) whether to allow the reverse resolution of the IP address of the visitor, when your application uses Request.getremotehost (), if you need only IP address, it is recommended to disable this, this can save the reverse domain name resolution time.

Maxpostsize: (default=2097152 that 2MB) the maximum allowable POST upload data size (in bytes), for general Web sites, such as writing comments to write the site, the default 2MB is enough, but if the site with pictures and even file upload function, It needs to be determined according to the specific circumstances.

Protocol: Type of connector, Tomcat 6 has the following options

1.org.apache.coyote.http11.http11protocol: Abbreviated as "Http/1.1″, this is the default connector, a guest network connection requires a thread, concurrent performance is relatively low."

2.org.apache.coyote.http11.http11nioprotocol:nio Connector, a non-blocking socket operating mode of the connector, concurrency performance is good, pure Java implementation.

3.ORG.APACHE.COYOTE.HTTP11.HTTP11APRPROTOCOL:APR Connector, the so-called APR is the Web server used by most servers on the network, Apache Http server used by the library, Tomcat Recommended in the production environment, the specific methods described below.

Sslenabled: (Default=false) to set whether the current connector uses secure SSL transport and, if set to true, the following two properties should be set: Scheme= "https" (default=http) can be set to HTTP or HTTPS. Secure= "true" (Default=false).

Redirectport: When a user accesses a resource that is not HTTPS and the resource requires HTTPS access, Tomcat is automatically redirected to the HTTPS port, and generally HTTPS uses the TCP 443 port, so the general value "443″."

Adress: The IP address that the connector binds to, when a server has more than one IP address, you can specify the one that needs to be bound, and the default does not set the value of this property to represent all IP addresses that bind to the current server.

Compressablemimetype: (default= "Text/html,text/xml,text/plain") specifies the type of resource that requires gzip compression.

Compression: (Default=off) Whether gzip compression is enabled, the value On/off/force can be set to on, and gzip compression is enabled for the resource type specified by the Compressablemimetype property.

ConnectionTimeout: (default= "60000″") when the guest network is connected, the server waits for the first row of request headers to appear. The unit is milliseconds.

Executor: Specifies the name of the thread pool used by the current connector and, if specified, ignores other settings for the number of threads, such as MaxThreads.

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

Port= "80″: Binding port.

KeepAliveTimeout: (Default=connectiontimeout) The time that a visitor completes a request and maintains a network connection.

A simple Connector definition is as follows:

<connector port= "protocol=" http/1.1 "connectiontimeout=" 60000 "redirectport=" 443
           
Configuration of EXECUTOR

Executor is used to define a shared thread pool. By default, each Connector produces its own thread pool, and if you want multiple Connector to share a thread pool, you can first define a thread pool, such as:

<executor name= "Tomcatthreadpool" nameprefix= "catalina-exec-" maxthreads= "" minsparethreads= "
        4"/>

The above Connector configuration is then modified to add the executor attribute, and the modified configuration is as follows:

<connector executor= "Tomcatthreadpool"
               port= "
               protocol=" http/1.1 "connectiontimeout=" redirectport= "443"/>
HOST's configuration

A host configuration is a virtual host, for example, the following is a simple host configuration:

 

The Host configures the function of each property of the node:

1.name: Set up the domain name of the virtual host, such as localhost, the actual application should fill in the specific domain name, such as www.dog.com or dog.com, of course, if the virtual host is to the internal personnel access, you can also directly fill out the IP address of the server, such as 192.168.1.10.

2.autoDeploy: Whether automatic deployment is allowed, and the default value is true, means that Tomcat automatically detects file changes under the AppBase directory and automatically applies to the running WEB application.

3.unpackWARs: Set whether to automatically expand the war compression pack and run the WEB application, the default value is true.

4.appBase: Sets the path of the WEB application group. As mentioned earlier, a virtual host can be made up of multiple Web applications, so the appbase here should be the directory that prepares the set of Web applications, rather than the directory itself of a particular Web application (even if the virtual host is comprised of only one Web application). The value of the AppBase property can be relative to the Tomcat installation directory, or it can be an absolute path, and it needs to be noted that the path must be tomcat-accessible and that Tomcat installed through the Arch Linux source runs through Tomcat, 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.dog.com:

The WebApps directory created by default when Tomcat is installed is visible below the directory/var/lib/tomcat6 and is created in/VAR/LIB/TOMCAT6 to facilitate the management of the documentation for the virtual host we are about to create:

$ sudo mkdir dog

Then create the directory root in the dog directory, and then create the file in root index.html (content casually).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.