Tomcat之虚拟主机
1.创建存放网页的目录
mkdir -p /web/{a,b}
2.添加jsp文件
vi /web/a/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP a page</title>
</head>
<body>
<% out.println("Welcome to the test site, http://www.a.com"); %>
</body>
</html>
vi /web/b/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP b page</title>
</head>
<body>
<% out.println("Welcome to the test site, http://www.b.com"); %>
</body>
</html>
3.添加主机信息
cd /opt/apache-tomcat-8.5.90/conf/
vi server.xml
1)定位到 </Engine>上面:
添加如下信息:
<Host name="www.a.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context docBase="/web/a" path="" reloadable="false" />
<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="webapps" unpackWARs="true" autoDeploy="true">
<Context docBase="/web/b" path="" reloadable="false" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
2)将之前的host注释掉
<!-- <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> -->
systemctl restart tomcat
4.域名映射
vim /etc/hosts
192.168.233.132 www.a.com www.b.com
5.在linux中的firefox中访问
www.a.com:8080
查看错误日志: