1. 程式人生 > >tomcat 配置多個虛擬域名訪問

tomcat 配置多個虛擬域名訪問

為了使得同一個tomcat下部署不同的專案,即使專案中工程同名。則需要在其配置檔案sever.xml中增加Host選項,以匹配不同的域名。

1、增加虛擬域名,window上修改host檔案 C:\Windows\System32\drivers\etc\hosts   樣例: 127.0.0.1 yiyahai.com

2、修改tomcat檔案server.xml

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
  
  
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <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">
 
         
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />


      </Host>


 <Host name="yiyahai.com"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
<Context path="enterprisetv" docBase="/enterprisetv/manager"/>  
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />


      </Host>


   </Engine>