Tomcat6配置多虚拟主机



实现效果:

http://localhost 访问一个项目例如一个助学网。

http://localhost1 访问一个项目例如一个办公系统

实现方案,需要修改两个地方

一个是C:\WINDOWS\system32\drivers\etc\hosts文件,改为

127.0.0.1       localhost
127.0.0.1       localhost1

另一个要改的就是server.xml,修改后如下:
Java代码

   1. <?xml version='1.0' encoding='utf-8'?> 
   2.  
   3. <Server port="8005" shutdown="SHUTDOWN"> 
   4.  
   5.   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 
   6.  
   7.   <Listener className="org.apache.catalina.core.JasperListener" /> 
   8.  
   9.   <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> 
  10.   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 
  11.  
  12.   
  13.   <GlobalNamingResources> 
  14.     
  15.     <Resource name="UserDatabase" auth="Container" 
  16.               type="org.apache.catalina.UserDatabase" 
  17.               description="User database that can be updated and saved" 
  18.               factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
  19.               pathname="conf/tomcat-users.xml" /> 
  20.   </GlobalNamingResources> 
  21.  
  22.   
  23.   <Service name="Catalina"> 
  24.    
  25.     
  26.     <Connector port="80" protocol="HTTP/1.1"  
  27.                connectionTimeout="20000"  
  28.                redirectPort="8443" /> 
  29.     
  30.     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 
  31.  
  32.     <Engine name="Catalina" defaultHost="localhost"> 
  33.  
  34.       <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
  35.              resourceName="UserDatabase"/> 
  36.  
  37.       <Host name="localhost" appBase="webapps" 
  38.              unpackWARs="true" autoDeploy="true" debug="0"> 
  39.     <Context path="" docBase="E:\Tomcat6\webapps\YangFan\" reloadable="true" crossContext="true"/> 
  40.       </Host> 
  41.  
  42.       <Host name="localhost1" appBase="webapps" 
  43.              unpackWARs="true" autoDeploy="true" debug="0"> 
  44.     <Context path="" docBase="E:\Tomcat6\webapps\hiccOffice\" reloadable="true" crossContext="true"/> 
  45.       </Host> 
  46.  
  47.     </Engine> 
  48.  
  49.   </Service> 
  50. </Server> 

<?xml version='1.0' encoding='utf-8'?>

<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.mbeans.ServerLifecycleListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />


  <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="80" 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.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <Host name="localhost" appBase="webapps"
             unpackWARs="true" autoDeploy="true" debug="0">
    <Context path="" docBase="E:\Tomcat6\webapps\YangFan\" reloadable="true" crossContext="true"/>
      </Host>

      <Host name="localhost1" appBase="webapps"
             unpackWARs="true" autoDeploy="true" debug="0">
    <Context path="" docBase="E:\Tomcat6\webapps\hiccOffice\" reloadable="true" crossContext="true"/>
      </Host>

    </Engine>

  </Service>
</Server>



ok,重启tomcat6,就可以访问了,前提是保证写的路径正确。

如果本机已经申请了域名,那么只需要修改server.xml就可以。

只需要把localhost和localhost1分别改为不同的域名就OK了。十分的简单。

你可能感兴趣的:(C++,c,xml,windows,C#)