Tomcat之虚拟主机

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("Wel***e to the test site, http://www.a.***"); %>
</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("Wel***e to the test site, http://www.b.***"); %>
</body>
</html>

3.添加主机信息
cd /opt/apache-tomcat-8.5.90/conf/

vi server.xml 

1)定位到 </Engine>上面:

添加如下信息:

<Host name="www.a.***" appBase="webapps" unpackWARs="true" autoDeploy="true">
    <Context docBase="/web/a" path="" reloadable="false" />
    <Valve className="org.apache.catalina.valves.A***essLogValve" directory="logs"
        prefix="localhost_a***ess_log" suffix=".txt"
        pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

<Host name="www.b.***" appBase="webapps" unpackWARs="true" autoDeploy="true">
    <Context docBase="/web/b" path="" reloadable="false" />
    <Valve className="org.apache.catalina.valves.A***essLogValve" directory="logs"
        prefix="localhost_a***ess_log" suffix=".txt"
        pattern="%h %l %u %t &quot;%r&quot; %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" />
         -->
 
         <!-- A***ess log processes all example.
              Documentation at: /docs/config/valve.html
              Note: The pattern used is equivalent to using pattern="***mon" -->
     <!--    <Valve className="org.apache.catalina.valves.A***essLogValve" directory="logs"
                prefix="localhost_a***ess_log" suffix=".txt"
                pattern="%h %l %u %t &quot;%r&quot; %s %b" />  -->
 
 <!--      </Host> -->

systemctl restart tomcat

4.域名映射

vim /etc/hosts

192.168.233.132 www.a.*** www.b.***

5.在linux中的firefox中访问

www.a.***:8080

查看错误日志:

转载请说明出处内容投诉
CSS教程_站长资源网 » Tomcat之虚拟主机

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买