Tomcat虚拟主机
部署
bash
[root@localhost webapps]# cd ../conf
[root@localhost conf]# pwd
/usr/local/tomcat/conf
[root@localhost conf]# vim server.xml
#增加虚拟主机配置,添加以下:
<Host name="www.a.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="/web/a" path="" reloadable="flase" />
<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="flase" />
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
#虚拟主机目录及文件准备
[root@localhost conf]# mkdir -p /web/{a,b}
[root@localhost conf]# vim /web/a/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP a page</title>
</head>
<body>
<% out.println("Welocome to test site,http://www.a.com");%>
</body>
</html>
[root@localhost conf]# vim /web/b/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP a page</title>
</head>
<body>
<% out.println("Welocome to test site,http://www.b.com");%>
</body>
</html>
重启tomcat
[root@localhost ~]# systemctl restart tomcat
在Windows下的C:\Windows\System32\drivers\etc中的hosts文件中添加
重启服务