分享

tomcat部署多个项目,公网通过域名解析访问

 FareWe11 2011-01-13
首先需要有多个域名,同时指向一个IP地址。

例如:域名:www., www.等等。

           解析到一个公网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." appBase="aaa"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
      </Host>

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

     <Host name="www." 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.

127.0.0.1     www.

127.0.0.1     localhost


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多