天天看點

Tomcat部署多個項目----阿裡雲伺服器Linux作業系統

如果就是我們就是一般部署多個項目的話,就直接把war包放入Tomcat的webapps中,然後運作Tomcat就會自動解壓,

Tomcat部署多個項目----阿裡雲伺服器Linux作業系統

然後localhost:8080/demo/login.jsp; localhost:8080/demo2/login.jsp 就可以進行通路

這個很簡單,因為不用綁定域名等一些操作,就不多說了

然後我們這邊主要說一下關于伺服器-Linux作業系統的Tomcat部署多個項目:

我使用的工具是xftp 和 xshell(如果這兩個工具不熟的話以及去掉8080端口可以觀看我的上一篇文章傳送門)

然後我同樣是把war包給放進Tomcat的webapps中,然後在xshell中運作Tomcat(或者你重新開機伺服器也是可以的),就會自動解壓,如下:。(這是xftp中的Tomcat的webapps中)

Tomcat部署多個項目----阿裡雲伺服器Linux作業系統

servlet.xml:的配置,注意最後面的 Engine 以及 host 節點

<Engine name="Catalina" defaultHost="www.abc.com">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <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>

      <Host name="www.abc.com"  appBase="webapps"  unpackWARs="true"  autoDeploy="true">
         <Content path=""  docBase="demo"  debug="0"  reloadable="false"/>
         <Content path=""  docBase="demo2"  debug="0"  reloadable="false"/>
         <Value className="org.apache.catalina.valves.AccessLogValue" directory="logs"
                prefix="www.abc.com_access_log." suffix=".txt"    
                pattern="%h %l %u %c &quot;%r&quot; %s %b" />
      </Host>

    </Engine>
  </Service>
</Server>
           

然後我們就可以通路了:

www.abc.com/demo/index.jsp

www.abc.com/demo1/index.jsp

當然如果你想www.abc.com就通路你的首頁的話,就直接把解壓後檔案放進webapps的ROOT檔案夾中,沒有嘗試,不過目前估計是這樣的。。

如發現錯誤還請指正,以免誤導了别人,共同成長,謝謝大家