一个tomcat下 部署多个web应用 ,通过不同的端口访问
1.把webapps复制一份,命名为webapps2
2.把war包1号放到webapps下
3.把war包2号放到webapps2下
4.修改 apache-tomcat-8.5.41\conf\server.xml (记得先备份)
<?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>
<!-- 第一套web应用 -->
<Service name="community">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443"/>
<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="/usr/local/tomcat/webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/community/"
prefix="community_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
<!-- 第二套web应用 -->
<Service name="community2">
<!-- 1.改端口 port -->
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443"/>
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<!-- 2.改war包位置 appBase -->
<Host name="localhost" appBase="/usr/local/tomcat/webapps2"
unpackWARs="true" autoDeploy="true">
<!-- 2.改日志文件名 directory、prefix -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/community2/"
prefix="community2_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
5.启动 apache-tomcat-8.5.41\bin\startup.sh
6.访问
http://localhost:8080/community/userInfo/hello
http://localhost:8081/community/userInfo/hello
成功!!!
7.tomcat 配置文件详解
https://www.cnblogs.com/starhu/p/5599773.html