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

说明:

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

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

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

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.aaa.com"  appBase="aaa"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
      </Host>

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

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

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

附:如果进行本地测试。则需加如下配置:

C:/Windows/System32/drivers/etc/hosts(Vista系统下路径,其他操作系统可能不一样)

# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

127.0.0.1     www.aaa.com

127.0.0.1     www.bbb.com

127.0.0.1     localhost

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值