tomcat部署多项目server.xmll配置

首先,我们以windows为例,其他系统类似。

 第一种情况:多项目使用同一域名,我们以两个项目为例。

 为了配置方便, 我们先把这两个项目的war包放到tomcat的webapps目录下。

 我们现在看一下配置:

 

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!--  
  3.   Licensed to the Apache Software Foundation (ASF) under one or more  
  4.   contributor license agreements.  See the NOTICE file distributed with  
  5.   this work for additional information regarding copyright ownership.  
  6.   The ASF licenses this file to You under the Apache License, Version 2.0  
  7.   (the "License"); you may not use this file except in compliance with  
  8.   the License.  You may obtain a copy of the License at  
  9.   
  10.       http://www.apache.org/licenses/LICENSE-2.0  
  11.   
  12.   Unless required by applicable law or agreed to in writing, software  
  13.   distributed under the License is distributed on an "AS IS" BASIS,  
  14.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  15.   See the License for the specific language governing permissions and  
  16.   limitations under the License.  
  17. --><!-- Note:  A "Server" is not itself a "Container", so you may not  
  18.      define subcomponents such as "Valves" at this level.  
  19.      Documentation at /docs/config/server.html  
  20.  --><Server port="8005" shutdown="SHUTDOWN">  
  21.   <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>  
  22.   <!-- Security listener. Documentation at /docs/config/listeners.html  
  23.   <Listener className="org.apache.caectalina.security.SecurityListener" />  
  24.   -->  
  25.   <!--APR library loader. Documentation at /docs/apr.html -->  
  26.   <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>  
  27.   <!-- Prevent memory leaks due to use of particular java/javax APIs-->  
  28.   <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>  
  29.   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>  
  30.   <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>  
  31.   
  32.   <!-- Global JNDI resources  
  33.        Documentation at /docs/jndi-resources-howto.html  
  34.   -->  
  35.   <GlobalNamingResources>  
  36.     <!-- Editable user database that can also be used by  
  37.          UserDatabaseRealm to authenticate users  
  38.     -->  
  39.     <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>  
  40.   </GlobalNamingResources>  
  41.   
  42.   <!-- A "Service" is a collection of one or more "Connectors" that share  
  43.        a single "Container" Note:  A "Service" is not itself a "Container",  
  44.        so you may not define subcomponents such as "Valves" at this level.  
  45.        Documentation at /docs/config/service.html  
  46.    -->  
  47.   <Service name="Catalina">  
  48.     <Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>  
  49.     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>  
  50.     <Engine defaultHost="localhost" name="Catalina">  
  51.       <Realm className="org.apache.catalina.realm.LockOutRealm">  
  52.         <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>  
  53.       </Realm>  
  54.   
  55.      <!-- 访问路径:www.test.com.cn/test-one   
  56.             www.test.com.cn/test-two  
  57.       -->  
  58.       <Host appBase="webapps" autoDeploy="true" name="www.test.com.cn" unpackWARs="true">  
  59.   
  60.            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/>  
  61.   
  62.            <Context docBase="D:\tomcat\webapps\test-one" path="/test-one" reloadable="true" source="org.eclipse.jst.jee.server:test-one"/>  
  63.        <Context docBase="D:\tomcat\webapps\test-two" path="/test-two" reloadable="true" source="org.eclipse.jst.jee.server:test-two"/>  
  64.       </Host>  
  65.         
  66.     </Engine>  
  67.   </Service>  
  68. </Server>  

我们再看一下不同项目使用不同域名,以两个项目为例:

[html]  view plain  copy
  1. <?xml version='1.0' encoding='utf-8'?>  
  2.   
  3. <Server port="8007" shutdown="SHUTDOWN">  
  4.   <Listener className="org.apache.catalina.startup.VersionLoggerListener" />  
  5.     
  6.     
  7.   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />  
  8.   <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->  
  9.   <Listener className="org.apache.catalina.core.JasperListener" />  
  10.   <!-- Prevent memory leaks due to use of particular java/javax APIs-->  
  11.   <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />  
  12.   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />  
  13.   <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />  
  14.   
  15.   <!-- Global JNDI resources  
  16.        Documentation at /docs/jndi-resources-howto.html  
  17.   -->  
  18.   <GlobalNamingResources>  
  19.     <!-- Editable user database that can also be used by  
  20.          UserDatabaseRealm to authenticate users  
  21.     -->  
  22.     <Resource name="UserDatabase" auth="Container"  
  23.               type="org.apache.catalina.UserDatabase"  
  24.               description="User database that can be updated and saved"  
  25.               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"  
  26.               pathname="conf/tomcat-users.xml" />  
  27.   </GlobalNamingResources>  
  28.   
  29.   <!-- A "Service" is a collection of one or more "Connectors" that share  
  30.        a single "Container" Note:  A "Service" is not itself a "Container",  
  31.        so you may not define subcomponents such as "Valves" at this level.  
  32.        Documentation at /docs/config/service.html  
  33.    -->  
  34.   <Service name="Catalina">  
  35.     <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/>  
  36.     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />  
  37.     <Engine name="Catalina" defaultHost="localhost">   
  38.       <Realm className="org.apache.catalina.realm.LockOutRealm">  
  39.         <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>  
  40.       </Realm>  
  41.   
  42.       <!-- 访问路径:www.test.com.cn  -->  
  43.      <Host name="www.test.com.cn"  appBase="webapps" unpackWARs="true" autoDeploy="true">  
  44.         <Context path="/" docBase="D:\tomcat\webapps\test-three" allowLinking="true" />  
  45.           
  46.         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
  47.                prefix="localhost_access_log." suffix=".txt"  
  48.                pattern="%h %l %u %t "%r" %s %b" />  
  49.   
  50.       </Host>  
  51.   
  52.       <!-- 访问路径:www.test2.com.cn  -->  
  53.      <Host name="www.test2.com.cn"  appBase="webapps" unpackWARs="true" autoDeploy="true">  
  54.         <Context path="/" docBase="D:\tomcat\webapps\test-four" allowLinking="true" />  
  55.           
  56.         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
  57.                prefix="localhost_access_log." suffix=".txt"  
  58.                pattern="%h %l %u %t "%r" %s %b" />  
  59.   
  60.       </Host>  
  61.   
  62.   
  63.     </Engine>  
  64.   </Service>  
  65. </Server>  

我们启动服务器就可以访问了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值