1、server.xml组件类别
顶级组件:位于整个配置的顶层,如server。
容器类组件:可以包含其它组件的组件,如service、engine、host、context。
连接器组件:连接用户请求至tomcat,如connector。
<server> #表示一个运行于JVM中的tomcat实例。
<service> #服务。将connector关联至engine,因此一个service内部可以有多个connector,但只能有一个引擎engine。
<connector /> #接收用户请求,类似于httpd的listen配置监听端口的
<engine> #核心容器组件,catalina引擎,负责通过connector接收用户请求,并处理请求,将请求转至对应的虚拟主机host。
<host> #类似于httpd中的虚拟主机,
<context></context> #配置context的主要目的指定对应对的webapp的根目录。其还能为webapp指定额外的属性,如部署方式等。
</host>
<host>
<context></context>
</host>
</engine>
</service>
</server>
2、server.xml配置文件注释
<?xml version='1.0' encoding='utf-8'?>
<!--
<Server>元素代表整个容器,是Tomcat实例的顶层元素.它包含一个<Service>元素.并且它不能做为任何元素的子元素.
port指定Tomcat监听shutdown命令端口
shutdown指定终止Tomcat服务器运行时,发给Tomcat服务器的shutdown监听端口的字符串.该属性必须设置
-->
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<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服务组件-->
<Service name="Catalina">
<!-- Connector主要参数说明(见下面) -->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<!-- 详情常见(host参数详解)-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- 详情见扩展(Context参数说明 )-->
<Context path="" docBase="" debug=""/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
4、Connector主要参数说明
port:指定服务器端要创建的端口号,并在这个端口监听来自客户端的请求。
protocol:连接器使用的协议,支持HTTP和AJP。AJP(Apache Jserv Protocol)专用于tomcat与apache建立通信的, 在httpd反向代理用户请求至tomcat时使用(可见Nginx反向代理时不可用AJP协议)。
redirectPort:指定服务器正在处理http请求时收到了一个SSL传输请求后重定向的端口号
maxThreads:接收最大请求的并发数
connectionTimeout 指定超时的时间数(以毫秒为单位)
<Connector port=“8080” protocol=“HTTP/1.1”
maxThreads=“500” ----默认是200
connectionTimeout=“20000” ---------连接超时时间。单位毫秒
redirectPort=“8443” />
5、host参数详解
<Host name=“localhost” appBase=“webapps”
unpackWARs=“true” autoDeploy=“true”>
host:表示一个虚拟主机
name:指定主机名
appBase:应用程序基本目录,即存放应用程序的目录.一般为appBase="webapps",相对于CATALINA_HOME而言的,也可以写绝对路径。
unpackWARs:如果为true,则tomcat会自动将WAR文件解压,否则不解压,直接从WAR文件中运行应用程序
autoDeploy:在tomcat启动时,是否自动部署