tomcat部署多个项目,通过域名解析访问不同的网站

转摘自:http://qinyinbolan.blog.51cto.com/4359507/1211064


说明:

1.首先需要有多个域名,同时指向一个IP地址。

例如:域名:www.bbb.comwww.aaa.com等等。

          解析到一个公网IP地址:xxx.xxx.xxx.xxx

2.需要对tomcat下的conf下的"server.xml"进行配置
<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="8080" protocol="HTTP/1.1" 
              connectionTimeout="20000" 
              redirectPort="8443" URIEncoding="gbk" />
      <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

   <!--以下配置是关键-->
   <Engine name="Catalina" defaultHost="localhost">

     <!--默认通过localhost转发-->
     <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
            resourceName="UserDatabase"/>

      <!--以下是自带的转发-->
     <Host name="localhost" appBase="webapps"
           unpackWARs="true" autoDeploy="true"
           xmlValidation="false" xmlNamespaceAware="false">

     </Host>
    <!-- 在tomcat安装目录下新建文件夹aaa 与webapp同级,然后在该目录下新建Root,项目内容可放在这个位置 -->
   <Host name="www.qinyinbolan.com" appBase="aaa"
           unpackWARs="true" autoDeploy="true"
           xmlValidation="false" xmlNamespaceAware="false">
     </Host>

   <!-- 同上,在tomcat安装目录下新建文件夹bbb与webapp同级 , 然后在该目录下新建Root,项目内容可放在这个位置   -->

    <Host name="linux.qinyinbolan.com" appBase="bbb"
           unpackWARs="true" autoDeploy="true"
           xmlValidation="false" xmlNamespaceAware="false">
     </Host>

   </Engine>
</Service>
</Server>
这样,就可以访问多个项目,通过不同的域名进行。


备注说明:

appBase可以采用绝对路径。

<Host name="xx.com" appBase="D:webappxx.com"
           unpackWARs="true" autoDeploy="true"
           xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="D:webappxx.com" debug="0" reloadable="true" crossContext="true"></Context>
 </Host>


原文地址:https://www.cnblogs.com/ycpanda/p/3637225.html