一个tomcat配置多个端口多个项目

桃扇骨 2022-12-08 02:05 341阅读 0赞

第一种方式:

启动多个tomcat,修改不同的端口

第二种(复制一个service即可):

1、将要同时启动的项目放入不同的webapps文件夹中

format_png

2、修改tomcat安装目录下的conf—>setting.xml文件

  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. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- Note: A "Server" is not itself a "Container", so you may not
  17. define subcomponents such as "Valves" at this level.
  18. Documentation at /docs/config/server.html
  19. -->
  20. <Server port="80" shutdown="SHUTDOWN">
  21. <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  22. <!-- Security listener. Documentation at /docs/config/listeners.html
  23. <Listener className="org.apache.catalina.security.SecurityListener" />
  24. -->
  25. <!--APR library loader. Documentation at /docs/apr.html -->
  26. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  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. <!-- Global JNDI resources
  32. Documentation at /docs/jndi-resources-howto.html
  33. -->
  34. <GlobalNamingResources>
  35. <!-- Editable user database that can also be used by
  36. UserDatabaseRealm to authenticate users
  37. -->
  38. <Resource name="UserDatabase" auth="Container"
  39. type="org.apache.catalina.UserDatabase"
  40. description="User database that can be updated and saved"
  41. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  42. pathname="conf/tomcat-users.xml" />
  43. </GlobalNamingResources>
  44. <!-- A "Service" is a collection of one or more "Connectors" that share
  45. a single "Container" Note: A "Service" is not itself a "Container",
  46. so you may not define subcomponents such as "Valves" at this level.
  47. Documentation at /docs/config/service.html
  48. -->
  49. <!--
  50. 第一个项目,webapps,默认端口为8080
  51. -->
  52. <Service name="Catalina">
  53. <!--The connectors can use a shared executor, you can define one or more named thread pools-->
  54. <!--
  55. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
  56. maxThreads="150" minSpareThreads="4"/>
  57. -->
  58. <!-- A "Connector" represents an endpoint by which requests are received
  59. and responses are returned. Documentation at :
  60. Java HTTP Connector: /docs/config/http.html
  61. Java AJP Connector: /docs/config/ajp.html
  62. APR (HTTP/AJP) Connector: /docs/apr.html
  63. Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
  64. -->
  65. <Connector port="8080" protocol="HTTP/1.1"
  66. connectionTimeout="20000"
  67. redirectPort="8443" />
  68. <!-- A "Connector" using the shared thread pool-->
  69. <!--
  70. <Connector executor="tomcatThreadPool"
  71. port="8080" protocol="HTTP/1.1"
  72. connectionTimeout="20000"
  73. redirectPort="8443" />
  74. -->
  75. <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
  76. This connector uses the NIO implementation. The default
  77. SSLImplementation will depend on the presence of the APR/native
  78. library and the useOpenSSL attribute of the
  79. AprLifecycleListener.
  80. Either JSSE or OpenSSL style configuration may be used regardless of
  81. the SSLImplementation selected. JSSE style configuration is used below.
  82. -->
  83. <!--
  84. <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
  85. maxThreads="150" SSLEnabled="true">
  86. <SSLHostConfig>
  87. <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
  88. type="RSA" />
  89. </SSLHostConfig>
  90. </Connector>
  91. -->
  92. <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
  93. This connector uses the APR/native implementation which always uses
  94. OpenSSL for TLS.
  95. Either JSSE or OpenSSL style configuration may be used. OpenSSL style
  96. configuration is used below.
  97. -->
  98. <!--
  99. <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
  100. maxThreads="150" SSLEnabled="true" >
  101. <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
  102. <SSLHostConfig>
  103. <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
  104. certificateFile="conf/localhost-rsa-cert.pem"
  105. certificateChainFile="conf/localhost-rsa-chain.pem"
  106. type="RSA" />
  107. </SSLHostConfig>
  108. </Connector>
  109. -->
  110. <!-- Define an AJP 1.3 Connector on port 8009 -->
  111. <Connector port="8011" protocol="AJP/1.3" redirectPort="8443" />
  112. <!-- An Engine represents the entry point (within Catalina) that processes
  113. every request. The Engine implementation for Tomcat stand alone
  114. analyzes the HTTP headers included with the request, and passes them
  115. on to the appropriate Host (virtual host).
  116. Documentation at /docs/config/engine.html -->
  117. <!-- You should set jvmRoute to support load-balancing via AJP ie :
  118. <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
  119. -->
  120. <Engine name="Catalina" defaultHost="localhost">
  121. <!--For clustering, please take a look at documentation at:
  122. /docs/cluster-howto.html (simple how to)
  123. /docs/config/cluster.html (reference documentation) -->
  124. <!--
  125. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  126. -->
  127. <!-- Use the LockOutRealm to prevent attempts to guess user passwords
  128. via a brute-force attack -->
  129. <Realm className="org.apache.catalina.realm.LockOutRealm">
  130. <!-- This Realm uses the UserDatabase configured in the global JNDI
  131. resources under the key "UserDatabase". Any edits
  132. that are performed against this UserDatabase are immediately
  133. available for use by the Realm. -->
  134. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  135. resourceName="UserDatabase"/>
  136. </Realm>
  137. <Host name="localhost" appBase="webapps"
  138. unpackWARs="true" autoDeploy="true">
  139. <!-- SingleSignOn valve, share authentication between web applications
  140. Documentation at: /docs/config/valve.html -->
  141. <!--
  142. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  143. -->
  144. <!-- Access log processes all example.
  145. Documentation at: /docs/config/valve.html
  146. Note: The pattern used is equivalent to using pattern="common" -->
  147. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  148. prefix="localhost_access_log" suffix=".txt"
  149. pattern="%h %l %u %t "%r" %s %b" />
  150. </Host>
  151. </Engine>
  152. </Service>
  153. <!-- 第二个项目,webapps1,端口号8081
  154. 再修改redirectPort:8444、
  155. appBase="webapps1"
  156. -->
  157. <Service name="Catalina">
  158. <Connector port="8081" protocol="HTTP/1.1"
  159. connectionTimeout="20000"
  160. redirectPort="8444" />
  161. <Engine name="Catalina" defaultHost="localhost">
  162. <Realm className="org.apache.catalina.realm.LockOutRealm">
  163. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  164. resourceName="UserDatabase"/>
  165. </Realm>
  166. <Host name="localhost" appBase="webapps1" unpackWARs="true" autoDeploy="true">
  167. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  168. prefix="localhost_access_log." suffix=".txt"
  169. pattern="%h %l %u %t "%r" %s %b" />
  170. </Host>
  171. </Engine>
  172. </Service>
  173. <!-- 第三个项目,webapps2,端口号8082
  174. 再修改redirectPort:8445、
  175. appBase="webapps2"
  176. -->
  177. <Service name="Catalina">
  178. <Connector port="8082" protocol="HTTP/1.1"
  179. connectionTimeout="20000"
  180. redirectPort="8445" />
  181. <Engine name="Catalina" defaultHost="localhost">
  182. <Realm className="org.apache.catalina.realm.LockOutRealm">
  183. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  184. resourceName="UserDatabase"/>
  185. </Realm>
  186. <Host name="localhost" appBase="webapps2" unpackWARs="true" autoDeploy="true">
  187. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  188. prefix="localhost_access_log." suffix=".txt"
  189. pattern="%h %l %u %t "%r" %s %b" />
  190. </Host>
  191. </Engine>
  192. </Service>
  193. </Server>

发表评论

表情:
评论列表 (有 0 条评论,341人围观)

还没有评论,来说两句吧...

相关阅读

    相关 解决tomcat端口冲突

           我在一台PC机上安装了两个tomcat,需要同时启动,每个tomcat上跑一个程序,但是现在提示端口号冲突,需要手动更改。 需要修改三个地方: 1、首先: 在