Tomcat8.0配置虚拟主机

一个tomcat里放多个项目,想把每个项目通过单独的域名来访问,这就需要将tomcat配置虚拟主机。

网上找了好多例子,但是tomcat都不能启动了,试了好多方法,最后搞定了,现在分享出来,希望能帮到更多的人。

1.首先是将域名解析到你的项目的ip地址。

2.在conf/server.xml中有这样一段代码

    <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" />
        -->

        <!-- 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 "%r" %s %b" />

      </Host>
	  
    </Engine>

需要在<Host>.......</Host>下面在,</Engine>上面加两外一个<Host></Host>

<Host name="video.xalibrary.com" appBase="webapps/video">
	<Context path="" docBase="" debug="0" reloadable="false" crossContext="true"/> 
</Host>

其中的name就是你的域名,appBase就是网站的目录,doBase路径如果为空,那网站根目录就是appBase所指向的路径,及webapps/video。

关于reloadable=true设置了这个属性,运行在tomcat下环境下的程序,源代码一做改动,tomcat服务会自动重启。我们在调试程序的时候一般都不会设置relaodable="true",太不方便了!如果你设置了reloadable="false",或者没有设置这个属性,只有当你在添加,删除,重命名方法或实例字段的时候才要求服务重启,适合你调试程序。

配置好的地址如下
http://video.xalibrary.com/

这个网站可以免费看大部分会员的视频



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值