Tomcat部署多个项目分别占用独自端口

1. 需求描述

  • 现在有两个项目,要部署到同一个服务器内的同一个Tomcat里,两个项目各自占用独立的端口号
  • A项目占用8080,且放置在ROOT文件夹,B项目占用8888,放置在Webapps

2. 解决方案

  • 修改Tomcat/conf内的server.xml配置文件
  • 添加一个Host节点,如下所示:



<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="8080" 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">
                    <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="自己起个名">

          <Connector port="8888" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
          <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
          <Engine name="自己起个名" 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="camelia_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
                    <Context path="" docBase="D:\apache-tomcat-9.0.29\webapps\CameliaAPI" workDir="D:\apache-tomcat-9.0.29\webapps\CameliaAPI\logs" />
               Host>
          Engine>
     Service>
Server>

你可能感兴趣的:(JavaWeb)