Tomcat的总体架构概览2(v8.5)(用server.xml的视角解读)

<?xml version="1.0" encoding="UTF-8"?>
<!-- 1、此处是Server的定义与配置。整个tomcat有且仅有唯一一个Server -->
<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>
	<!-- 2、此处是service的定义 -->
  <Service name="Catalina">
	<!-- 2.1、此处是Connector连接器的配置,用于配置端口,协议等信息 -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
	<!-- 2.2、此处是Container(Engine+Host+Context)的定义与配置,最上层Engine定义,命名为Catalina-->
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
	  <!-- 2.2.1虚拟主机的定义,(localhost,会适配所有其他Host未匹配的域名或地址,也用于本地路径的访问。) -->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
      </Host>
	  <!-- 我们也可以定义一个另外的虚拟主机,来针对不同的域名(name值要与域名解析时候设置的域名相同,webapp2是与webapp同级的目录。) -->
      <Host name="www.jangle.xyz"  appBase="webapps2"
            unpackWARs="true" autoDeploy="true">
		<!-- 2.2.2Context的自定义,我们定义了一个Context,它的web应用目录是绝对路径D:/jangle,通过www.jangle.xyz/jan 进行访问-->
		<Context docBase="D:/jangle" path="/jan"></Context>
      </Host>
    </Engine>
  </Service>
</Server>

server.xml的详细配置办法,与参数介绍,后续整理完成再写。

引用:https://blog.csdn.net/Bof_jangle/article/details/104405720

发布了129 篇原创文章 · 获赞 20 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/Bof_jangle/article/details/104491562
今日推荐