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
[root@CentOS6 ~]# curl www.b.com:8080
[root@CentOS6 ~]# curl www.c.com:8080
www.c.com
标签:www,虚拟主机,tomcat,实现,root,vim,html,com From: https://www.cnblogs.com/biaoming534/p/16608332.html