zoukankan      html  css  js  c++  java
  • tomcat多站点部署

    我们可能会有这种场景,一个tomcat想部署两个web工程,说白了就是公用一个端口,那怎么办呢?就是多站点部署,具体步骤如下(这里以linux平台举例):

    1)先修改server.xml(conf/server.xml)

      

     1  <!--For clustering, please take a look at documentation at:
     2           /docs/cluster-howto.html  (simple how to)
     3           /docs/config/cluster.html (reference documentation) -->
     4       <!--
     5       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
     6       -->
     7 
     8       <!-- Use the LockOutRealm to prevent attempts to guess user passwords
     9            via a brute-force attack -->
    10       <Realm className="org.apache.catalina.realm.LockOutRealm">
    11         <!-- This Realm uses the UserDatabase configured in the global JNDI
    12              resources under the key "UserDatabase".  Any edits
    13              that are performed against this UserDatabase are immediately
    14              available for use by the Realm.  -->
    15         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
    16                resourceName="UserDatabase"/>
    17       </Realm>
    18 
    19       <Host name="localhost"  appBase="webapps"
    20             unpackWARs="true" autoDeploy="true">
    21 
    22         <!-- SingleSignOn valve, share authentication between web applications
    23              Documentation at: /docs/config/valve.html -->
    24         <!--
    25         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    26         -->
    27 
    28         <!-- Access log processes all example.
    29              Documentation at: /docs/config/valve.html
    30              Note: The pattern used is equivalent to using pattern="common" -->
    31         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
    32                prefix="localhost_access_log" suffix=".txt"
    33                pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    34 
    35       </Host>
    36         <Host name="aa.com"  appBase="/data/aa/apache-tomcat-8.5.8/webapps/aa" unpackWARs="true" autoDeploy="true"></Host>
    37        <Host name="bb.com"  appBase="/data/bb/apache-tomcat-8.5.8/webapps/bb" unpackWARs="true" autoDeploy="true"></Host> 
    38    </Engine>

      ops:千万记得19-35行记得保留,不然war包不会解压,通过站点名或ip直接去访问会404.

      上面新增的两个host就是两个站点,aa和bb分别于不同的web工程。

    2)去conf/Catalina下创建相应的站点目录:

      

    mkdir -p conf/Catalina/aa.com
    mkdir -p conf/Catalina/bb.com
    这里的aa和bb对应上面server.xml host的name属性

    3)建立域名绑定:

      在/etc/hosts中加入域名映射

      

    127.0.0.1 localhost
    127.0.0.1 aa.com
    127.0.0.1 bb.com

    4)将war包上传至server.xml中host标签appBase对应的路径

    重启ok,完毕!

  • 相关阅读:
    P2114 [NOI2014]起床困难综合症(二进制)
    P4577 [FJOI2018]领导集团问题
    P5290 [十二省联考2019]春节十二响(堆+启发式合并)
    P2048 [NOI2010]超级钢琴(RMQ+堆+贪心)
    P4890 Never·island(dp)
    P2617 Dynamic Rankings(树状数组套主席树)
    P5241 序列(滚动数组+前缀和优化dp)
    P3243 [HNOI2015]菜肴制作(拓扑排序)
    【LeetCode每天一题】Combination Sum II(组合和II)
    【LeetCode每天一题】Combination Sum(组合和)
  • 原文地址:https://www.cnblogs.com/dbaxyx/p/6797363.html
Copyright © 2011-2022 走看看