tomcat版本:9.0.0.0-423
需求:通过8080端口访问webapps中的项目,通过8090端口访问webapps1中的项目
方法:在conf/server.xml文件中添加service节点
以下是service节点(tomcat默认配置,已删除注释)
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
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">
<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>
第1步:结束tomcat进程,在conf/server.xml文件中service节点后新增一个service节点,appBase="webapps1",http监听端口8090,Service name、Engine name为"Catalina1"
<Service name="Catalina1">
<Connector port="8090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina1" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps1"
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>
</Engine>
</Service>
第2步:在tomcat目录下新建webapps1文件夹,将项目拷贝到webapps1,重启tomcat。
tomcat端口说明:https://blog.csdn.net/BigDevil_/article/details/105242985
注:同一浏览器访问同一服务器中同一tomcat下多个项目或访问多个tomcat的多个项目,存在sesssion覆盖和丢失的问题。
sesssion共享方案:https://blog.csdn.net/u012383839/article/details/79756368
解决sesssion覆盖问题:https://cloud.tencent.com/developer/article/1703162