Tomcat多域名站点配置(即一个服务器部署多个同端口【如同80端口】的站点)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenbetter1996/article/details/82345196

想在一个IP的服务器上部署多个使用同端口的不同域名站点,因为是web项目,常用端口为80端口。情况如下。

一个安装了tomcat的服务器主机(如IP为120.99.99.99 公网IP)   

如有两个域名  www.a.com    www.b.com  站点内容不一样,现在需要都部署在这个服务器上,同为80端口

(地址栏输入www.a.com 和www.b.com内容不一样,此为其中一个和输入120.99.99.99效果一样 【即defaultHost】)

<Service name="Catalina">

    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    
    <Engine name="Catalina" defaultHost="zhuowenzhi.com">
  
      <Realm className="org.apache.catalina.realm.LockOutRealm"> 
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>
      
      <!-- @lin 9.2 23:11 
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="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>
      -->
      
      <!-- @Lin the follow just for test -->
      <Host name="zhuowenzhi.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
	<Context path="" docBase="zhi" debug="0" reloadable="true"/>
      </Host>
      
      <Host name="chenguanlin.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
 	<Context path="" docBase="lin" debug="0" reloadable="true"/>
      </Host>

    </Engine>
  </Service>

此为其中的关键一部分  <Engine> 标签中的属性defaultHost要修改为其下Host子标签中的一个,也就是使用IP也可以打开的那个。

<Host name="域名" appBase="webapps" unpackWARs="true" autoDeploy="true">
	<Context path="" docBase="项目名" debug="0" reloadable="true"/>
</Host>

(当然,上面的域名是假设的,想要测试只需要修改主机的hosts文件,添加映射就行)

效果

扫描二维码关注公众号,回复: 3149381 查看本文章

猜你喜欢

转载自blog.csdn.net/chenbetter1996/article/details/82345196