在同一个 Tomcat 中部署多个不同端口的项目

这里就以部署两个项目为例。

首先修改server.xml文件,找到Server块,是这个样子的:

<Server>
  <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 &quot;%r&quot; %s %b" />
        </Host>
    </Engine>
  </Service>
</Server>

我们把里面的Service块复制一份放到下面,修改ServicenameEnginenameHostappBaseConnectorport。依次是服务名,引擎名,项目文件夹名,端口。ServiceEnginename最好一样。我改完后如下:

<Server>
  <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 &quot;%r&quot; %s %b" />
        </Host>
    </Engine>
  </Service>
  
  <Service name="weixin">
    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
			   
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

    <Engine name="weixin" defaultHost="localhost">
        <Realm className="org.apache.catalina.realm.LockOutRealm">
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                   resourceName="UserDatabase"/>
        </Realm>
        <Host name="localhost"  appBase="webapps_weixin"
              unpackWARs="true" autoDeploy="true">
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="localhost_access_log." suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
        </Host>
    </Engine>
  </Service>
</Server>

然后在Tomcat根目录下复制webapps文件夹,重命名成刚刚设置的Host里的appBase。再在conf目录下复制一份Catalina文件夹,重命名成设置的Enginename

可以把webapps里的manage文件夹也拷过去,就有了图形管理界面。接下来重启Tomcat,就大功告成了。