本文将解决以下问题:
本例中 系统:Linux version 3.10.0-514.el7.x86_64
、tomcat版本:8.0.30.0
、jdk 版本:jdk1.8.0
实现方法: 修改/增加server.xml
文件中以下配置
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/root/tomcat/apache-tomcat-8.0.30/fantasy" debug="0" privileged="true" reloadable="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>
解释 :
http://ip:port
、如果非空则访问路径:http://ip:port/path
。WEB-INF/classes
和Web-INF/lib
目录CLASS文件的改变,如果监视到有class文件被更新,服务器自动重新加载Web应用,这样我们可以在不重启tomcat的情况下改变应用程序实现方法: 修改server.sml文件中Connector 的 port 属性,访问方式同上
<Connector port="2727" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8445" />
解释:
HTTP/1.1
是默认值,等效于org.apache.coyote.http11.Http11Protocol
实现方法: server.sml文件中增加service元素
<Service name="Catalina2">
<Connector port="2727" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8445" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8445" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="fantasy" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/root/tomcat/apache-tomcat-8.0.30/fantasy" debug="0" privileged="true" reloadable="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>
</Engine>
</Service>
解释:
一个 service 代表一个web应用实例 ;同一个 server.xml 文件中每个 service 的 name 值不能相同;同一个 server.xml 文件中每个 service 的 redirectPort 、port 值不能相同
<?xml version="1.0" encoding="UTF-8"?>
<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 name="Catalina">
<Connector port="80" 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 name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/root/tomcat/apache-tomcat-8.0.30/webapps/ROOT" debug="0" privileged="true" reloadable="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>
</Engine>
</Service>
<Service name="Catalina2">
<Connector port="2727" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8445" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8445" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="fantasy" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/root/tomcat/apache-tomcat-8.0.30/fantasy" debug="0" privileged="true" reloadable="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>
</Engine>
</Service>
</Server>
手机扫一扫
移动阅读更方便
你可能感兴趣的文章