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

 

相关文章

一 、安装solr 环境说明:centos 7.3,solr 6.6,zookeeper3...
tomcat 日志说明 配置文件server.xml 默认日志格式为 推荐使...
在实际生产环境中,tomcat的 catalina.out日志默认是不切割的...
简介: SSL 协议的3个特性: 保密:通过SSL链接传输的数据是...
遵循Java Servlet 规范第4节中的建议 ,Apache Tomcat实现了...