微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

6.tomcat实现多虚拟主机

6.tomcat实现多虚拟主机

 

实验前准备

[root@CentOS8 ~]# systemctl start tomcat

[root@CentOS8 ~]# systemctl status tomcat

[root@CentOS8 ~]# hostnamectl set-hostname tomcat

 

6.1准备数据目录,注意那个ROOT

[root@tomcat ~]#mkdir /data/website{1,2,3}/ROOT -pv

[root@tomcat ~]#vim /data/website1/ROOT/index.html

www.a.com

[root@tomcat ~]#vim /data/website2/ROOT/index.html

www.b.com

[root@tomcat ~]#vim /data/website3/ROOT/index.html

www.c.com

 

#设置权限

[root@tomcat ~]# chown -R tomcat.tomcat /data/website{1,2,3}/

 

6.2修改配置

[root@tomcat ~]#cd /usr/local/tomcat/

[root@tomcat tomcat]#vim conf/server.xml

             available for use by the Realm.  -->

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

               resourceName="UserDatabase"/>

      </Realm>

      <Host name="www.a.com"  appBase="/data/website1" 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>

      <Host name="www.b.com"  appBase="/data/website2" unpackWARs="true" autoDeploy="true">

      </Host>

      <Host name="www.c.com"  appBase="/data/website3" unpackWARs="true" autoDeploy="true">

      </Host>

    </Engine>

  </Service>

</Server>

 

 

重启Tomcat服务

[root@tomcat tomcat]#systemctl restart tomcat

 

 

6.3测试访问

[root@CentOS6 ~]#vim /etc/hosts

10.0.0.7 www.a.com www.b.com www.c.com

 

[root@CentOS6 ~]# curl www.a.com:8080

www.a.com

 

[root@CentOS6 ~]# curl www.b.com:8080

www.b.com

 

[root@CentOS6 ~]# curl www.c.com:8080

www.c.com

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐