同一台Tomcat的多域名绑定

要求:同一台Tomcat

目标:

1.通过 localhost/项目名 访问Tomcat的webapp下的项目
2.通过 www.aaa.com 和 www.bbb.com 分别访问Tomcat下的不同域名的虚拟主机

一、修改server.xml文件下的端口号
在这里插入图片描述
二、项目位置
在这里插入图片描述
三、多域名配置

将server .xml文件中的<Host’>‘信息复制粘贴在’<‘engine>’</‘engine> 标签之中,并修改如下,其中参数name默认为localhost,修改为你自己的域名 并且在’<‘host>’</‘host> 标签之间添加’<‘Context docBase=“项目路径” path="" reloadable=“true” > 标签,’<'Context>中参数path为你的项目根目录,如项目在该tomcat下直接空着就行,docBase是基于appBase下的,可以写绝对路径,也可以写相对路径,可以把项目放到ROOT文件夹下,这样地址就不用带项目名

其实,context标签只是起到连接作用,不用也可以,只需把项目的内容(即除去外层的项目名文件夹)直接放到ROOT下运行就可以了,效果一样

 <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->
		
		<!--<Context path="" docBase="hugh" debug="0" reloadable="true" crossContext="true" />-->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <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="www.aaa.com"  appBase="aaa"
            unpackWARs="true" autoDeploy="true">
		<Context path="" docBase="ROOT\AAA" debug="0" reloadable="true" crossContext="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="www.bbb.com"  appBase="bbb"
            unpackWARs="true" autoDeploy="true">
			<Context path="" docBase="ROOT\BBB" debug="0" reloadable="true" crossContext="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>
	  
    </Engine>


四、域名解析

由于没有买域名,就只能通过修改hosts文件使用单机版玩玩

hosts路径 :C:\Windows\System32\Drivers\etc\hosts

在这里插入图片描述
五、让域名解析生效

重启或用cmd命令运行 ipconfig /flushdns

在这里插入图片描述
六、测试
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值