linux-tomcat实现多虚拟主机
作者:互联网
设备
centos7 10.0.0.17 tomcat
Windows host文件添加域名解析 做客户端访问
10.0.0.17 www.lia.com www.lib.com www.lic.com
创建多虚拟主机的文件的访问路径
[root@centos7-liyj /usr/local/tomcat]#mkdir /data/webapps{1,2,3} 创建目录 [root@centos7-liyj /usr/local/tomcat]#mkdir /data/webapps{1,2,3}/ROOT [root@centos7-liyj /usr/local/tomcat]#cd [root@centos7-liyj /data]#tree . ├── webapps1 │ └── ROOT ├── webapps2 │ └── ROOT └── webapps3 └── ROOT 6 directories, 0 files [root@centos7-liyj /data]#chown -R tomcat.tomcat /data/webapps1 #修改权限为tomcat [root@centos7-liyj /data]#chown -R tomcat.tomcat /data/webapps2 [root@centos7-liyj /data]#chown -R tomcat.tomcat /data/webapps3 [root@centos7-liyj /data]#echo www.lia.com > /data/webapps1/ROOT/index.html #建立访问文件 [root@centos7-liyj /data]#echo www.lib.com > /data/webapps2/ROOT/index.html [root@centos7-liyj /data]#echo www.lic.com > /data/webapps3/ROOT/index.html
修改tomcat配置文件
[root@centos7-liyj /usr/local/tomcat]#vim conf/server.xml <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> <Host name="www.lia.com" appBase="/data/webapps1/" #修改name为要访问的域名,appBase修改为域名访问的文件路径 unpackWARs="true" autoDeploy="true"> </Host> <Host name="www.lib.com" appBase="/data/webapps2/" unpackWARs="true" autoDeploy="true"> </Host> <Host name="www.lic.com" appBase="/data/webapps3/" unpackWARs="true" autoDeploy="true"> </Host>
重启服务
[root@centos7-liyj /usr/local/tomcat]#systemctl restart tomcat
测试
标签:虚拟主机,tomcat,data,centos7,ROOT,liyj,linux,root 来源: https://www.cnblogs.com/lyj1023/p/16390065.html