Tomcat配置虚拟目录、多域名、多个Http监听端口

原文地址:http://www.cnblogs.com/Lawson/archive/2012/09/03/2669122.html

< Server  port ="8005"  shutdown ="SHUTDOWN" >
   < Listener  className ="org.apache.catalina.core.AprLifecycleListener"  SSLEngine ="on"   />
   < Listener  className ="org.apache.catalina.core.JasperListener"   />
   < Listener  className ="org.apache.catalina.core.JreMemoryLeakPreventionListener"   />
   < Listener  className ="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"   />
   < Listener  className ="org.apache.catalina.core.ThreadLocalLeakPreventionListener"   />

   < GlobalNamingResources >
     < Resource  name ="UserDatabase"  auth ="Container"
              type
="org.apache.catalina.UserDatabase"
              description
="User database that can be updated and saved"
              factory
="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname
="conf/tomcat-users.xml"   />
   GlobalNamingResources >

   < Service  name ="Catalina" >
     < Connector  port ="8088"  protocol ="HTTP/1.1"
               connectionTimeout
="20000"
               redirectPort
="8443"   />

     < Connector  port ="8009"  protocol ="AJP/1.3"  redirectPort ="8443"   />
     < Engine  name ="Catalina"  defaultHost ="localhost" >
       < Realm  className ="org.apache.catalina.realm.LockOutRealm" >
         < Realm  className ="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName
="UserDatabase" />
       Realm >

       < Host  name ="localhost"   appBase ="webapps"
            unpackWARs
="true"  autoDeploy ="true" >
     < Alias >www.test3.com Alias > 

         < Valve  className ="org.apache.catalina.valves.AccessLogValve"  directory ="logs"
               prefix
="localhost_access_log."  suffix =".txt"
               pattern
="%h %l %u %t "%r" %s %b"   />
         < Context  path =""  docBase ="D:\TomCat7.0\testapp\TestWebliu"   />  

       Host >
      
       < Host  name ="www.test1.com"   appBase ="testapp"
            unpackWARs
="true"  autoDeploy ="true" >
       Host >
     Engine >
   Service >
  
    
   < Service  name ="Catalina2" >

     < Connector  port ="880"  protocol ="HTTP/1.1"
               connectionTimeout
="20000"
               redirectPort
="8443"   />

     < Connector  port ="8010"  protocol ="AJP/1.3"  redirectPort ="8443"   />

     < Engine  name ="Catalina2"  defaultHost ="localhost" >

       < Realm  className ="org.apache.catalina.realm.LockOutRealm" >
         < Realm  className ="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName
="UserDatabase" />
       Realm >

       < Host  name ="localhost"   appBase ="webapps"
            unpackWARs
="true"  autoDeploy ="true" >

         < Valve  className ="org.apache.catalina.valves.AccessLogValve"  directory ="logs"
               prefix
="localhost_access_log."  suffix =".txt"
               pattern
="%h %l %u %t "%r" %s %b"   />
         < Context  path =""  docBase ="D:\TomCat7.0\testapp\TestWebliu"   />  

       Host >
      
       < Host  name ="www.test2.com"   appBase ="testapp"
            unpackWARs
="true"  autoDeploy ="true" >
            
         < Context  path ="/TestWeb2"  docBase ="D:\TomCat7.0\testapp\TestWeb2"   />  
         < Context  path =""  docBase ="D:\TomCat7.0\testapp\TestWebliu"   />  
      
       Host >
     Engine >
   Service >
Server >
复制代码


即:server下面可以有多个service,用于配置不同监听端口

service下面可以有多个Host,用于配置该端口下的不同域名

Host里可以包含多个Context,用于配置该端口该域名下的不同虚拟目录


上面的配置,可以用下面链接访问:

http://127.0.0.1:8088/

http://www.test3.com:8088/

http://www.test1.com:8088/TestWeb2/

http://www.test2.com:880/

http://127.0.0.1:880/

test1,2,3都是我hosts里指向了本地的。


你可能感兴趣的:(tomcat)