Reprinted: http://www.blogjava.net/baoyaer/articles/107278.html
Tomcat server structure
This file describes how to start Tomcat server
<Server>
<Listener/>
<Globanamingresources>
</Globanamingresources
<Service>
<Connector/>
<Engine>
<Logger/>
<Realm/>
<Host>
<Logger/>
<Context/>
</Host>
</Engine>
</Service>
</Server>
Element name |
Attribute |
Explanation |
Server |
Port |
Specifies a port to listen for requests to disable tomcat. |
Shutdown |
Specifies the command string sent to the port |
Service |
Name |
Service name |
Connector (indicating the connection between the client and the Service) |
Port |
Specify the port number to be created on the server and listen to requests from the client at this break. |
Minprocessors |
Number of threads created when the server is started to process requests |
Maxprocessors |
Maximum number of threads that can be created to process requests |
Enablelookups |
If the value is true, you can call request. getremotehost () for DNS query to obtain the actual Host Name of the remote client. If the value is false, no DNS query is performed, but the IP address is returned. |
Redirectport |
Specifies the port number to be redirected after the server receives an SSL transfer request when processing an HTTP request. |
Acceptcount |
Specify the number of threads that can be used to process requests, and the number of requests that can be placed in the processing queue. Requests that exceed this number will not be processed. |
Connectiontimeout |
Time-out period (in milliseconds) |
Engine (indicates the request processing machine in the specified service to receive and process requests from ctor) |
Defaulthost |
Specifies the default host name for processing requests. It must be at least the same as the name attribute value of one of the host elements. |
Context (a web application, usually a war file. For details about war, see servlet specifications) |
Docbase |
Application Path or war file storage path |
Path |
Indicates the prefix of the URL of the Web application. The requested URL is http: // localhost: 8080/path /**** |
Reloadable |
This property is very important, if it is true, Tomcat will automatically detect changes to the application's/WEB-INF/lib and/WEB-INF/classes directory, automatically load the new application, we can change the application without restarting tomcat. |
Host (a virtual host) |
Name |
Specify the Host Name |
Appbase |
The basic application directory, that is, the directory where the application is stored. |
Unpackwars |
If this parameter is set to true, Tomcat automatically decompress the war file. Otherwise, the application is directly run from the war file. |
Logger (indicating logs, debugging, and error messages) |
Classname |
Specifies the class name used by logger. This class must implement the org. Apache. Catalina. logger interface. |
Prefix |
Specify the log file prefix |
Suffix |
Specify the suffix of the log file |
Timestamp |
If true, time is added to the log file name, as shown in the following example: localhost_log.001-10-04.txt |
Realm (indicates the database that stores the user name, password, and role) |
Classname |
Specifies the class name used by realm. This class must implement the org. Apache. Catalina. realm Interface |
Valve (similar to logger, its prefix and suffix attributes are interpreted as the same as those in logger) |
Classname |
Specifies the class name used by valve. For example, the org. Apache. Catalina. Valves. accesslogvalve class can be used to record application access information. |
Directory |
Location where log files are stored |
Pattern |
There are two values: Remote Host Name or IP address, user name, date, string of the first line of request, HTTP response code, and number of bytes sent. The combined method has more values than the common method. |
<Server> element
It represents the entire container and is the top-level element of the Tomcat instance. by Org. apache. catalina. server interface to define. it contains a <service> element. it cannot be a child element of any element.
<! -- A "server" is an independent component that provides a complete JVM. It can contain one or more
"Service" instance. The server listens to the shutdown command on the specified port.
Note: A "server" itself is not a "container", so here you
Sub-components such as "valves" or "loggers" cannot be defined
-->
<! -- Start server
Wait for the command to close at Port 8005
If the "shutdown" string is received, the server is disabled.
-->
Test:
Telnet local host 8005
Input: Shutdown
Result: Tomcat is disabled.
<Server port = "8005" shutdown = "shutdown" DEBUG = "0">
1> classname specifies the class that implements the org. Apache. Catalina. server interface. The default value is org. Apache. Catalina. Core. standardserver.
2> port: Specifies the port for Tomcat to listen to the shutdown command. When the server is terminated, the shutdown command must be issued on the machine where the Tomcat server is located. This attribute is required.
3> shutdown specifies the string of the shutdown listening port sent to the Tomcat server when the Tomcat server is terminated. This attribute must be set
<Service> element
This element is defined by the org. Apache. Catalina. service interface. It contains one <engine> element and one or more <connector> elements that share the same engine element.
<! -- A "service" is one or more "ors" that share a single "container" (container"
Combination (therefore, the application is visible in the container ). Generally, this container is an "engine"
(Engine), but this is not necessary.
Note: A "service" is not a container, so you cannot define it at this level.
Such as "valves" or "loggers" sub-components.
-->
<! -- Standalone service of Tomcat
A service is a collection of connectors.
They share an engine to process all requests received by the ctor.
-->
<Service name = "Catalina">
<Service name = "Apache">
The first <service> process all Web client requests directly received by the Tomcat server.
The second <service> process all Web client requests forwarded by the apahce server.
1> classname specifies the class that implements the org. apahce. Catalina. service interface. The default value is org. apahce. Catalina. Core. standardservice.
2> name defines the service name
<Connector> element
Defined by the connector interface. The <connector> element represents the deliverable that actually interacts with the customer program. It is responsible for receiving customer requests and returning response results to the customer.
<! -- A "connector" (connector) represents the endpoint required for receiving and responding to a request. Each connection
The connector processes the request through the related "container.
By default, a non-ssl http/1.1 Connector is bound to port 8080. You can also
Follow the instructions below and cancel the comments for the second connector entry, and create
Ssl http/1.1 Connector. The following steps are required to enable SSL support:
Configure SSL instructions for more details ):
* If your JDK is a version earlier than 1.3 or 1.3, download and install JSSE 1.0.2 or later.
Set the JAR file to the "$ java_home/JRE/lib/EXT" directory.
* Execute the command with a "changeit:
% Java_home % \ bin \ keytool-genkey-alias tomcat-keyalg RSA (Windows)
$ Java_home/bin/keytool-genkey-alias tomcat-keyalg RSA (UNIX)
To generate its own certificate private key.
By default, DNS queries are feasible when a web application calls a request. This will create
Therefore, you can set "enablelookups" to "false" to disable DNS.
Query. When the DNS query is disabled, request. getremotehost () will return a request containing the remote client IP Address
Address string.
-->
<! -- Coyote HTTP/1.1 Connector
Classname: The org ctor implementation class is org. Apache. Coyote. tomcat4.coyoteconne.
Port: listening for HTTP 8080 requests from client browser at port 8080. If you change to 80, you only need to enter http: // localhost /.
Protocol: Set the HTTP protocol. The default value is HTTP/1.1.
Minsparethreads: this connector ctor creates five threads to wait for customer requests. Each request is handled by one thread.
Maxsparethread: sets the maximum number of threads on the listening port. This value also determines the maximum number of threads that the server can respond to customer requests at the same time. The default value is 200.
Acceptcount: when the number of existing threads reaches 75, the client requests are queued. When the number of requests in the queue exceeds 100, the connection refused error is returned for subsequent requests.
Redirectport: when the customer requests https, the request is forwarded to port 8443.
Enablelookups: if it is set to true, domain name resolution is supported. You can resolve the IP address to the host name. The web application calls the request. getremotehost method to return the client host name. The default value is true.
Connectiontimeout: defines the timeout time for establishing a client connection. If the value is-1, the time for establishing a client connection is not limited.
Other attributes
-->
<Connector Port = "8080" maxthread = "50" minsparethreads = "25" maxsparethread = "75" enablelookups = "false" redirectport = "8443" acceptcount = "100" DEBUG =" 0 "connectiontimeout =" 20000 "disableuploadtimeout =" true "/>
<Connection Port = "8009" enablelookups = "false" redirectport = "8443" DEBUG = "0" protocol = "AJP/1.3"/>
The first connector element defines an HTTP connector, which receives HTTP requests through port 8080, and the second connector element defines a JD connector, it receives requests forwarded by other servers through port 8009.
<Engine> element
Each service element can only have one engine element. It processes the customer requests received by all <connector> elements in the same <service>. These are defined by the org. apahce. Catalina. Engine interface.
<! -- An "engine" indicates the entry point for processing each request (within Catalina ). This tomcat
To analyze the HTTP header information contained in the request and send the request to the appropriate host.
Or virtual host. -->
<! -- Engine is used to process HTTP requests received by ctor
It matches the request with its own virtual host and forwards the request to the corresponding host for processing.
The default virtual host is localhost.
-->
<Engine name = "Catalina" defaulthost = "localhost" DEBUG = "0">
1> classname specifies the class that implements the engine interface. The default value is standardengine.
2> defaulthost specifies the default host name for processing the customer. This host must be defined in the 3> name defines the engine name
<Engine> can contain the following elements: <logger>, <realm>, <value>, and
<Host> element
It is defined by the host interface. An engine element can contain multiple
<! -- Define the default Virtual Host
Note: Validation of XML mode will not work with xerces 2.2.
-->
<! -- Virtual host localhost
Appbase: Specifies the virtual host directory. You can specify an absolute directory or a relative directory relative to <catalina_home>. if this option is not available, the default value is <catalina_home>/webapps. it matches the path of the request and its own context, and transfers the request to the corresponding context for processing.
Autodeploy: If this parameter is set to true, it indicates that when the Tomcat service is running, files under the appbase can be monitored. If a new Web application is added, the Web application will be released automatically.
Unpackwars: If this option is set to true, the war file of the Web application is expanded to an open directory structure before running. If it is set to false, the war file is run directly.
Alias: Specifies the host alias. You can specify multiple aliases.
Deployonstartup: If this parameter is set to true, all web applications under the appbase directory will be automatically published when the Tomcat server is started. if the server. XML does not have the corresponding <context> element. The default context of Tomcat is used.
-->
<Host name = "localhost" DEBUG = "0" appbase = "webapps" unpackwars = "true" autodeploy = "true">
The <Logger>, <realm>, <value>, <context>
<Context> element
It is defined by the context interface. is the most frequently used element. each <context element represents a single web application running on the VM. one A corresponding context represents the web application itself. The servlet container creates
<! -- Context corresponds to a web app
Path: The Path Name of the context is "", so the context is the default context of the host.
Docbase: the root directory of the context is webapps/mycontext/
Reloadable: If this property is set to true, the Tomcat server will monitor changes to the class file in the WEB-INF/classes and web-INF/lib directory while running. if a class file is updated, the server automatically reloads the web application.
Usenaming: Specifies whether JNDI is supported. The default value is true.
Indicates whether the session is supported through cookies. The default value is true.
-->
<Context Path = "" docbase = "mycontext" DEBUG = "0"/>
Tomcat server processes an HTTP request
Assume that the request from the customer is:
HTTP: /localhost: 8080/wsota/wsota_index.jsp
1) The request is sent to the local port 8080, which is obtained by coyote HTTP/1.1 Connector
2) connector submits the request to the engine of the Service to process it, and waits for a response from the engine.
3) The engine obtains the request localhost/wsota/wsota_index.jsp, matching all the virtual host hosts it owns.
4) The engine matches the host named localhost (the request is handed over to the host even if the match fails, because the host is defined as the default host of the engine)
5) the localhost obtains the request/wsota/wsota_index.jsp and matches all the context
6) The host matches the context in the/wsota path. (if no match is found, submit the request to the context with the path name "" for processing)
7) obtain the request/wsota_index.jsp from the context of Path = "/wsota" and find the corresponding servlet in its mapping table.
8) the context matches the servlet whose URL pattern is *. jsp, which corresponds to the jspservlet class.
9) construct the httpservletrequest object and the httpservletresponse object, and call the jspservlet doget or dopost method as parameters.
10) Context returns the httpservletresponse object after execution to the host
11) The host returns the httpservletresponse object to the engine.
12) the engine returns the httpservletresponse object to Connector
13) connector returns the httpservletresponse object to the client browser.