tomcat文件中server.xml 实例说明
# 这是server类, 指定一个tomcat的应用实例
<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.JasperListener" />
<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">
# 这是http连接器,响应用户请求
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
# 这是ajp连接器,响应用户请求
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
# 这是Engine,解析用户请求,请求指定默认的虚拟主机为localhost
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
# 这是默认的虚拟主机localhost
<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 "%r" %s %b" />
</Host>
# 这里是第一个自定义的虚拟主机
<Host name="www.uplooking.com" appBase="/app/java"
unpackWARs="true" autoDeploy="true">
</Host>
# 这里是第二个自定义的虚拟主机
<Host name="www.home.com" appBase="/app/home"
unpackWARs="true" autoDeploy="true">
# 这里是用来定义虚拟主机的日志的,通常而言,日志格式需要格式化输出,使得tomcat的日志与httpd的日志一样,可以放在ELK中进行处理
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="uplooking_log" suffix=".log" pattern="%h %l %u %t %r %s %b %D %{Cookie}i %{User-Agent}i %{a}r/>
# 这里的Context组件中定义的path路径就相当于一个URI的映射,访问的目录为/data/app,这里需要注意的是在/data/app目录中,不能把资源放在ROOT目录下,只能放在/data/app目录下。也就是说浏览器访问的URL为:192.168.43.10:8080/app,访问文件系统上的资源是/data/app目录下的资源
<Context path="/app" docBase="/data/app" reloadable="true">
# 这里指定了访问控制的规则,deny表示拒绝访问
<Valve className="org.apache.catalina.valves.RemoteAddrValve" deny="192\.168\.23\.2"/>
</Context>
</Host>
</Engine>
</Service>
</Server>