一个Tomcat下部署两个,甚至多个项目

 

Tomcat目录下的结构如图:

 

第一步:Tomcat默认空间webapps,中已经存在一个项目了,此时要增加一个项目运行可以将原本webapps目录copa一份,

改名为webapp1(或者其他看实际情况),然后,将webapp1目录中原来的项目清除,加入你要部署的新项目

第二部:更改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.JasperListener" />
  <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">
    <!-- 此端口为8087,其他项目端口不能有冲突 -->
    <Connector port="8087" 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 docBase="testOne" path="/opt/tomcat7/webapps" reloadable="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>  
      <Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For" 
             protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https" />
    </Engine>
  </Service>
  <!-- 第二个项目 -->
  <Service name="Catalina">
  <!-- 此端口为8089,其他项目端口不能有冲突 -->
    <Connector port="8089" 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="webapps1" unpackWARs="true" autoDeploy="true">
        <!-- 配置:项目名,项目路径 -->
        <Context docBase="testTwo" path="/opt/tomcat7/webapps1" reloadable="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>
      <Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For" 
             protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https" />
    </Engine>
  </Service>
  
</Server>

第三部:重启Tomcat即可完成

此时,

访问第一个项目的路径为:localhost:8087/testOne

访问第二个项目的路径为:localhost:8089/testTwo

 

 

附:

了解下tomcat的几个主要端口:

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="60000"

redirectPort="8443" disableUploadTimeout="false"

executor="tomcatThreadPool" URIEncoding="UTF-8"/>

其中8080为HTTP端口,8443为HTTPS端口。

<Server port="8005" shutdown="SHUTDOWN">   

8005为远程停服务端口

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 

8009为AJP端口,APACHE能过AJP协议访问TOMCAT的8009端口。

 

posted @ 2019-01-15 15:25  云端观云  阅读(15956)  评论(0编辑  收藏  举报