zoukankan      html  css  js  c++  java
  • (转载)Tomcat 7通过设置不同的端口部署两个项目

    原文地址: https://www.jb51.net/article/95141.htm

    1、修改../tomcat/conf/server.xml,原有代码如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    <Service name="Catalina">
     
     <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
     
     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
     
     <Engine defaultHost="localhost" name="Catalina">
     
     <Realm className="org.apache.catalina.realm.LockOutRealm">
     <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
     </Realm>
     
     <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
     <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>
     </Host>
     
     </Engine>
     </Service>

    2、添加新端口号,代码如下:

    注意修改Service name; Connector port; Engine name; Host appBase

     1  <Service name="Catalina1">
     2 
     3     <!--The connectors can use a shared executor, you can define one or more named thread pools-->
     4     <!--
     5     <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
     6         maxThreads="150" minSpareThreads="4"/>
     7     -->
     8 
     9 
    10     <!-- A "Connector" represents an endpoint by which requests are received
    11          and responses are returned. Documentation at :
    12          Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
    13          Java AJP  Connector: /docs/config/ajp.html
    14          APR (HTTP/AJP) Connector: /docs/apr.html
    15          Define a non-SSL HTTP/1.1 Connector on port 8080
    16     -->
    17     <Connector port="8090" protocol="HTTP/1.1"
    18                connectionTimeout="20000"
    19                redirectPort="8443" URIEncoding="UTF-8"/>
    20     <!-- A "Connector" using the shared thread pool-->
    21     <!--
    22     <Connector executor="tomcatThreadPool"
    23                port="8080" protocol="HTTP/1.1"
    24                connectionTimeout="20000"
    25                redirectPort="8443" />
    26     -->
    27     <!-- Define a SSL HTTP/1.1 Connector on port 8443
    28          This connector uses the BIO implementation that requires the JSSE
    29          style configuration. When using the APR/native implementation, the
    30          OpenSSL style configuration is required as described in the APR/native
    31          documentation -->
    32     <!--
    33     <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
    34                maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
    35                clientAuth="false" sslProtocol="TLS" />
    36     -->
    37 
    38     <!-- Define an AJP 1.3 Connector on port 8009 -->
    39     <Connector port="8100" protocol="AJP/1.3" redirectPort="8443" />
    40 
    41 
    42     <!-- An Engine represents the entry point (within Catalina) that processes
    43          every request.  The Engine implementation for Tomcat stand alone
    44          analyzes the HTTP headers included with the request, and passes them
    45          on to the appropriate Host (virtual host).
    46          Documentation at /docs/config/engine.html -->
    47 
    48     <!-- You should set jvmRoute to support load-balancing via AJP ie :
    49     <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    50     -->
    51     <Engine name="Catalina1" defaultHost="localhost">
    52 
    53       <!--For clustering, please take a look at documentation at:
    54           /docs/cluster-howto.html  (simple how to)
    55           /docs/config/cluster.html (reference documentation) -->
    56       <!--
    57       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
    58       -->
    59 
    60       <!-- Use the LockOutRealm to prevent attempts to guess user passwords
    61            via a brute-force attack -->
    62       <Realm className="org.apache.catalina.realm.LockOutRealm">
    63         <!-- This Realm uses the UserDatabase configured in the global JNDI
    64              resources under the key "UserDatabase".  Any edits
    65              that are performed against this UserDatabase are immediately
    66              available for use by the Realm.  -->
    67         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
    68                resourceName="UserDatabase"/>
    69       </Realm>
    70 
    71       <Host name="localhost"  appBase="webapps1"
    72             unpackWARs="true" autoDeploy="true">
    73             <Context path="" docBase="D:Strategy2.5webapps1ROOT" debug="0" reloadable="false" sessionCookiePath="" sessionCookieName=""/>
    74 
    75         <!-- SingleSignOn valve, share authentication between web applications
    76              Documentation at: /docs/config/valve.html -->
    77         <!--
    78         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    79         -->
    80 
    81         <!-- Access log processes all example.
    82              Documentation at: /docs/config/valve.html
    83              Note: The pattern used is equivalent to using pattern="common" -->
    84         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
    85                prefix="localhost_access_log." suffix=".txt"
    86                pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    87 
    88       </Host>
    89     </Engine>
    90   </Service>

    3、创建目录

         a. 创建需要部署的目录../Tomcat/webapps1,并将需要部署的项目拷贝至该目录;

         b. 创建配置文件目录../Tomcat/conf/Catalina1/localhost

    4、修改项目代码

    在我尝试的过程中发现一个比较容易出错的地方,就是最好修改web.xmllog4j.properties配置文件。

    其中web.xml文件,需要添加webAppRootKey,代码如下:

    1
    2
    3
    4
    5
    //上层节点是web-app
    <context-param>
     <param-name>webAppRootKey</param-name>
     <param-value>mos_ms.root</param-value>
     </context-param>

    log4j.properties,修改log4j.appender.org.apache.log4j.DailyRollingFileAppender.File的值,代码如下:

    1
    2
    3
    //具体位置自定义,但是需要在${catalina1.home}中
    log4j.appender.A=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.A.File=${catalina1.home}/logs/GYL_log/PurePro_

    5、做好相应的改动

    启动tomcat,webapps目录和webapps1目录的应用都会启动,可以根据不同的端口进行访问里面的项目;假设项目名称是MyApp,对于上述改动那么我们就可以使用以下地址访问:http://localhost:8080/MyApp 或者 http://localhost:8090/MyApp。

  • 相关阅读:
    「学习笔记」min_25筛
    HNOI2019游记
    【SDOI2017】数字表格
    【APIO2016】烟火表演
    【SCOI2015】小凸想跑步
    java Thread源码分析
    java ThreadGroup源码分析
    bean获取Spring容器
    spring 管理bean
    thinkphp5.0.19 request
  • 原文地址:https://www.cnblogs.com/bruce-he/p/9230717.html
Copyright © 2011-2022 走看看