一个tomcat服务器上部署多个项目,不同域名访问

时间:2022-09-17 16:14:23

我们一个服务器只按装了一个tomcat服务器,现在有多个项目或者多个域名访问,下面来进行配置

在这里我们只需要修改conf下的server.xml就好了

1.不同端口访问的内容相同

一个tomcat服务器上部署多个项目,不同域名访问
下面为其server.xml
[html]  view plain  copy
  1. <?xml version='1.0' encoding='utf-8'?>  
  2. <Server port="8005" shutdown="SHUTDOWN">  
  3.   <Listener className="org.apache.catalina.startup.VersionLoggerListener" />  
  4.   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />  
  5.   <Listener className="org.apache.catalina.core.JasperListener" />  
  6.   <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />  
  7.   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />  
  8.   <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />  
  9.   
  10.    
  11.   <GlobalNamingResources>  
  12.     <Resource name="UserDatabase" auth="Container"  
  13.               type="org.apache.catalina.UserDatabase"  
  14.               description="User database that can be updated and saved"  
  15.               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"  
  16.               pathname="conf/tomcat-users.xml" />  
  17.   </GlobalNamingResources>  
  18.   
  19.   <Service name="Catalina">  
  20.     <Connector port="8080" protocol="HTTP/1.1"  
  21.                connectionTimeout="20000"  
  22.                redirectPort="8443" />  
  23.     <Connector port="8099" protocol="HTTP/1.1"  
  24.                connectionTimeout="20000"  
  25.                redirectPort="8443" />  
  26.     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />  
  27.     <Engine name="Catalina" defaultHost="localhost">  
  28.       <Realm className="org.apache.catalina.realm.LockOutRealm">  
  29.         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"  
  30.                resourceName="UserDatabase"/>  
  31.       </Realm>  
  32.       <Host name="localhost"  appBase="webapps"  
  33.             unpackWARs="true" autoDeploy="true">  
  34.         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
  35.                prefix="localhost_access_log." suffix=".txt"  
  36.                pattern="%h %l %u %t "%r" %s %b" />  
  37.       </Host>  
  38.     </Engine>  
  39.   </Service>  
  40. </Server>  


2.不同的域名访问不同的内容,端口是相同的
一个tomcat服务器上部署多个项目,不同域名访问
下面为其server.xml
[html]  view plain  copy
  1. <?xml version='1.0' encoding='utf-8'?>  
  2. <Server port="8005" shutdown="SHUTDOWN">  
  3.   <Listener className="org.apache.catalina.startup.VersionLoggerListener" />  
  4.   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />  
  5.   <Listener className="org.apache.catalina.core.JasperListener" />  
  6.   <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />  
  7.   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />  
  8.   <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />  
  9.   
  10.    
  11.   <GlobalNamingResources>  
  12.     <Resource name="UserDatabase" auth="Container"  
  13.               type="org.apache.catalina.UserDatabase"  
  14.               description="User database that can be updated and saved"  
  15.               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"  
  16.               pathname="conf/tomcat-users.xml" />  
  17.   </GlobalNamingResources>  
  18.   
  19.   <Service name="Catalina">  
  20.     <Connector port="8080" protocol="HTTP/1.1"  
  21.                connectionTimeout="20000"  
  22.                redirectPort="8443" />  
  23.     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />  
  24.     <Engine name="Catalina" defaultHost="localhost">  
  25.       <Realm className="org.apache.catalina.realm.LockOutRealm">  
  26.         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"  
  27.                resourceName="UserDatabase"/>  
  28.       </Realm>  
  29.       <Host name="www.111.com"  appBase="webapps"  
  30.             unpackWARs="true" autoDeploy="true">  
  31.         <Context path="" docBase="onefolder" debug="0" reloadable="true" />       
  32.         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
  33.                prefix="localhost_access_log." suffix=".txt"  
  34.                pattern="%h %l %u %t "%r" %s %b" />  
  35.       </Host>  
  36.   
  37.     <Host name="www.222.com"  appBase="webapps"  
  38.         unpackWARs="true" autoDeploy="true">  
  39.       <Context path="" docBase="twofolder" debug="0" reloadable="true" />  
  40.         
  41.     <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
  42.            prefix="localhost_access_log." suffix=".txt"  
  43.            pattern="%h %l %u %t "%r" %s %b" />  
  44.   </Host>  
  45.   
  46.     </Engine>  
  47.   </Service>  
  48. </Server>  
注意:2个不同域名访问相同端口的内容不同,但是如果还会使用ip访问的话,还需要在加上一个Host,如:使用ip访问的话去访问onefolder;ip访问其host name就是localhost
[html]  view plain  copy
  1. <Host name="localhost"  appBase="webapps"  
  2.             unpackWARs="true" autoDeploy="true">  
  3.              <Context path="" docBase="onefolder" debug="0" reloadable="true" />  
  4.         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
  5.                prefix="localhost_access_log." suffix=".txt"  
  6.                pattern="%h %l %u %t "%r" %s %b" />  
  7.       </Host>  





3.不同的域名不同端口不同内容
一个tomcat服务器上部署多个项目,不同域名访问
一个tomcat服务器上部署多个项目,不同域名访问

下面是其server.xml
[html]  view plain  copy
  1. <?xml version='1.0' encoding='utf-8'?>  
  2. <Server port="8005" shutdown="SHUTDOWN">  
  3.   <Listener className="org.apache.catalina.startup.VersionLoggerListener" />  
  4.   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />  
  5.   <Listener className="org.apache.catalina.core.JasperListener" />  
  6.   <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />  
  7.   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />  
  8.   <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />  
  9.   
  10.    
  11.   <GlobalNamingResources>  
  12.     <Resource name="UserDatabase" auth="Container"  
  13.               type="org.apache.catalina.UserDatabase"  
  14.               description="User database that can be updated and saved"  
  15.               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"  
  16.               pathname="conf/tomcat-users.xml" />  
  17.   </GlobalNamingResources>  
  18.   
  19.   <Service name="Catalina1">  
  20.     <Connector port="8080" protocol="HTTP/1.1"  
  21.                connectionTimeout="20000"  
  22.                redirectPort="8443" />  
  23.     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />  
  24.     <Engine name="Catalina" defaultHost="localhost">  
  25.       <Realm className="org.apache.catalina.realm.LockOutRealm">  
  26.         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"  
  27.                resourceName="UserDatabase"/>  
  28.       </Realm>  
  29.       <Host name="www.111.com"  appBase="webapps"  
  30.             unpackWARs="true" autoDeploy="true">  
  31.         <Context path="" docBase="folder111" debug="0" reloadable="true" />       
  32.         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
  33.                prefix="localhost_access_log." suffix=".txt"  
  34.                pattern="%h %l %u %t "%r" %s %b" />  
  35.       </Host>  
  36.     </Engine>  
  37.   </Service>  
  38.   
  39.   <Service name="Catalina2">  
  40.     <Connector port="9090" protocol="HTTP/1.1"  
  41.                connectionTimeout="20000"  
  42.                redirectPort="8443" />  
  43.     <Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />  
  44.     <Engine name="Catalina" defaultHost="localhost">  
  45.       <Realm className="org.apache.catalina.realm.LockOutRealm">  
  46.         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"  
  47.                resourceName="UserDatabase"/>  
  48.       </Realm>  
  49.       <Host name="www.222.com"  appBase="webapps"  
  50.             unpackWARs="true" autoDeploy="true">  
  51.         <Context path="" docBase="folder222" debug="0" reloadable="true" />       
  52.         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
  53.                prefix="localhost_access_log." suffix=".txt"  
  54.                pattern="%h %l %u %t "%r" %s %b" />  
  55.       </Host>  
  56.     </Engine>  
  57.   </Service>  
  58. </Server>  




版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/baidu_32492845/article/details/79107960