1. 程式人生 > >tomcat下一個專案如何繫結多個域名

tomcat下一個專案如何繫結多個域名

<Host name="localhost" debug="0" appBase="D:\\Tomcat 5.0\\webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
       <Alias>localhost.com</Alias>
       <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs" prefix="localhost_log." suffix=".txt"
            timestamp="true"/>
        <Context path="" docBase="D:\\Tomcat 5.0\\webapps\\gg" reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>

<Host name="one.localhost" debug="0" appBase="D:\\Tomcat 5.0\\webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
       <Alias>one.localhost.com</Alias>
       <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs" prefix="localhost_log." suffix=".txt"
            timestamp="true"/>
       <Context path="" docBase="D:\\Tomcat 5.0\\webapps\\kk\\a" reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>

<Host name="two.localhost" debug="0" appBase="D:\\Tomcat 5.0\\webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
       <Alias>two.localhost.com</Alias>
       <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs" prefix="localhost_log." suffix=".txt"
            timestamp="true"/>
        <Context path="" docBase="D:\\Tomcat 5.0\\webapps\\kk\\b" reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>

因無域名解析伺服器,所以在hosts上配,來模擬dns解析.

10.1.1.241 localhost           指向gg資料夾
10.1.1.241 localhost.com       指向gg資料夾
10.1.1.241 one.localhost       指向a資料夾
10.1.1.241 one.localhost.com   指向a資料夾
10.1.1.241 two.localhost       指向b資料夾
10.1.1.241 two.localhost.com   指向b資料夾

經過多方面嘗試,終於在tomcat下配置成功了.

修改預設的應用時:改defaulthost,並將context的path置為空。

配置多個應用時:

如:http://localhost:8080/

        http://localhost:8080/first

        http://localhost:8080/second

對應的配置如下:

<Host name="localhost" debug="0" appBase="D:\\Tomcat 5.0\\webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
       <Alias>localhost.com</Alias>
       <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs" prefix="localhost_log." suffix=".txt"
            timestamp="true"/>
        <Context path="" docBase="D:\\Tomcat 5.0\\webapps\\Root" reloadable="true" caseSensitive="false" debug="0"></Context>

        <Context path="/first" docBase="D:\\Tomcat 5.0\\webapps\\first" reloadable="true" caseSensitive="false" debug="0"></Context>
        <Context path="/second" docBase="D:\\Tomcat 5.0\\webapps\\second" reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>