Home  >  Article  >  Backend Development  >  Detailed explanation of Server.xml content [Tomcat]

Detailed explanation of Server.xml content [Tomcat]

Y2J
Y2JOriginal
2017-04-24 10:57:581721browse

Structural diagram of Tomcat Server

##This file describes how to start Tomcat Server


                           
##unpackWARsIf it is true, tomcat will automatically decompress the WAR file, otherwise it will not decompress and run the application directly from the WAR file Logger (representing logs, debugging and error information)classNameSpecifies the class name used by the logger. This class must implement org.apache. catalina.Logger interfaceprefixSpecify the prefix of the log file
Element name

Attribute

Explanation

server port Specify a port, which is responsible for listening and closing tomcat request
shutdown Specifies the command string sent to the port
service name Specify the name of the service
Connector (representing the connection between the client and the service) port #Specify the server to create The port number, and listen for requests from the client on this port
minProcessors Processors created when the server starts Number of threads requested
##maxProcessors Maximum number of threads that can be created to process requests
enableLookups If true, you can get the actual host name of the remote client by calling request.getRemoteHost() to perform a DNS query. If it is false, DNS query will not be performed, but its ip address will be returned.
redirectPort The specified server is processing The port number to redirect after receiving an SSL transfer request when http request
acceptCount Specify when all can When all the threads used to process requests are used, the number of requests that can be placed in the processing queue. Requests exceeding this number will not be processed
connectionTimeout Specify the number of timeouts (in milliseconds)
Engine (indicates request processing in the specified service machine, receives and processes requests from Connector) defaultHost Specifies the default host name for processing requests, which is at least the same as The name attribute value of a host element is the same
Context (indicating a web application, usually a WAR file. For specific information about WAR, see the servlet specification) docBase The path of the application or the path where the WAR file is stored
path represents the prefix of the URL of this web application, so the requested URL is http://localhost:8080/path/****
reloadable This attribute is very important. If it is true, tomcat will automatically detect the application's /WEB-INF/lib and changes to the /WEB-INF/classes directory to automatically load new applications. We can change applications without restarting tomcat
host (Indicates a virtual host) name Specify the host name
appBase The application base directory, which is the directory where the application is stored
suffix Specify the suffix of the log file
timestamp If it is true, the time must be added to the log file name, as in the following example: localhost_log.001-10-04.txt
Realm (represents the database that stores usernames, passwords and roles) className Specifies the class used by Realm Name, this class must implement the org.apache.catalina.Realm interface
Valve (the function is similar to Logger, and its prefix and suffix attribute explanations are the same as those in Logger ) className Specify the class name used by Valve. For example, use the org.apache.catalina.valves.AccessLogValve class to record the application's Access information
directory Specify the location where the log file is stored
pattern has two values, the common mode records the remote host name or IP address, user name, date, the string requested in the first line, and the HTTP response Code, number of bytes sent. The combined method records more values ​​than the common method

元素 它代表整个容器,是Tomcat实例的顶层元素.由org.apache.catalina.Server接口来定义.它包含一个元素.并且它不能做为任何元素的子元素.

注意:一个“Server”自身不是一个“Container”(容器),因此在这里你 不可以定义诸如“Valves”或者“Loggers”子组件 –>

在端口8005处等待关闭命令 如果接受到”SHUTDOWN”字符串则关闭服务器 –>

测试: telnet localhost 8005 输入:SHUTDOWN 结果:关闭tomcat


1>className指定实现org.apache.catalina.Server接口的类.默认值为org.apache.catalina.core.StandardServer 2>port指定Tomcat监听shutdown命令端口.终止服务器运行时,必须在Tomcat服务器所在的机器上发出shutdown命令.该属性是必须的. 3>shutdown指定终止Tomcat服务器运行时,发给Tomcat服务器的shutdown监听端口的字符串.该属性必须设置

元素 该元素由org.apache.catalina.Service接口定义,它包含一个元素,以及一个或多个,这些Connector元素共享用同一个Engine元素

注意:一个“Service”自身不是一个容器,因此,在这个级别上你不可定义 诸如“Valves”或“Loggers”子组件。 –>

Service是一组Connector的集合 它们共用一个Engine来处理所有Connector收到的请求 –>

第一个处理所有直接由Tomcat服务器接收的web客户请求. 第二个处理所有由Apahce服务器转发过来的Web客户请求 .

1>className 指定实现org.apahce.catalina.Service接口的类.默认为org.apahce.catalina.core.StandardService 2>name定义Service的名字

元素 由Connector接口定义.元素代表与客户程序实际交互的给件,它负责接收客户请求,以及向客户返回响应结果.


第一个Connector元素定义了一个HTTP Connector,它通过8080端口接收HTTP请求;第二个Connector元素定义了一个JD Connector,它通过8009端口接收由其它服务器转发过来的请求.

元素 每个Service元素只能有一个Engine元素.处理在同一个中所有元素接收到的客户请求.由org.apahce.catalina.Engine接口定义.


1>className指定实现Engine接口的类,默认值为StandardEngine 2>defaultHost指定处理客户的默认主机名,在中的子元素中必须定义这一主机 3>name定义Engine的名字

可以包含如下元素, , ,

元素 它由Host接口定义.一个Engine元素可以包含多个元素.每个的元素定义了一个虚拟主机.它包含了一个或多个Web应用.


的相对目录.如果没有此项,默认 为/webapps. 它将匹配请求和自己的Context的路径,并把请求转交给对应的Context来处 理 autoDeploy:如果此项设为true,表示Tomcat服务处于运行状态时,能够监测appBase下的文件,如果有新有web应用加入进来,会自运发布这个WEB应用 unpackWARs:如果此项设置为true,表示把WEB应用的WAR文件先展开为开放目录结构后再运行.如果设为false将直接运行为WAR文件 alias:指定主机别名,可以指定多个别名 deployOnStartup:如果此项设为true,表示Tomcat服务器启动时会自动发布appBase目录下所有的Web应用.如果Web应用 中的server.xml没有相应的元素,将采用Tomcat默认的Context –> 

元素中可以包含如下子元素 , , , < Context>元素 它由Context接口定义.是使用最频繁的元素.每个可以包含多个元素.每个web应用有唯一 的一个相对应的Context代表web应用自身.servlet容器为第一个web应用创建一个


 
 

Tomcat Server处理一个http请求的过程

假设来自客户的请求为:

localhost:8080/wsota/wsota_index.jsp

1) 请求被发送到本机端口8080,被在那里侦听的Coyote HTTP/1.1 Connector获得 2) Connector把该请求交给它所在的Service的Engine来处理,并等待来自Engine的回应 3) Engine获得请求localhost/wsota/wsota_index.jsp,匹配它所拥有的所有虚拟主机Host 4) Engine匹配到名为localhost的Host(即使匹配不到也把请求交给该Host处理,因为该Host被定义为该Engine的默认主机) 5) localhost Host获得请求/wsota/wsota_index.jsp,匹配它所拥有的所有Context 6) Host匹配到路径为/wsota的Context(如果匹配不到就把该请求交给路径名为”"的Context去处理) 7) path=”/wsota”的Context获得请求/wsota_index.jsp,在它的mapping table中寻找对应的servlet Context匹配到URL PATTERN为*.jsp的servlet,对应于JspServlet类 9) 构造HttpServletRequest对象和HttpServletResponse对象,作为参数调用JspServlet的doGet或doPost方法 10)Context把执行完了之后的HttpServletResponse对象返回给Host 11)Host把HttpServletResponse对象返回给Engine 12)Engine把HttpServletResponse对象返回给Connector 13)Connector把HttpServletResponse对象返回给客户browser

The above is the detailed content of Detailed explanation of Server.xml content [Tomcat]. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn