zoukankan      html  css  js  c++  java
  • Tomcat定义虚拟主机案例

                    Tomcat定义虚拟主机案例

                                          作者:尹正杰

    版权声明:原创作品,谢绝转载!否则将追究法律责任。

    一.准备环境

    1>.创建web程序的根目录

    [root@yinzhengjie ~]# mkdir -pv /home/yinzhengjie/data/www/webapps/ROOT
    mkdir: created directory ‘/home/yinzhengjie/data/www’
    mkdir: created directory ‘/home/yinzhengjie/data/www/webapps’
    mkdir: created directory ‘/home/yinzhengjie/data/www/webapps/ROOT’
    [root@yinzhengjie ~]# 
    [root@yinzhengjie ~]# mkdir -pv /home/yinzhengjie/data/www/webapps/test
    mkdir: created directory ‘/home/yinzhengjie/data/www/webapps/test’
    [root@yinzhengjie ~]# 

    2>.编辑根目录的首页信息

    [root@yinzhengjie ~]# more /home/yinzhengjie/data/www/webapps/ROOT/index.jsp
    <%@ page language="java" %>
    <%@ page import="java.util.*" %>
    <html>
      <head>
        <title>JSP test page.</title>
      </head>
      <body>
        <% out.println("Yinzhengjie ! Hello,world!"); %>
      </body>
    </html>
    [root@yinzhengjie ~]# 
    [root@yinzhengjie ~]# more /home/yinzhengjie/data/www/webapps/test/index.jsp 
    <%@ page language="java" %>
    <%@ page import="java.util.*" %>
    <html>
      <head>
        <title>JSP test page.</title>
      </head>
      <body>
        <% out.println("www.yinzhengjie.org.cn"); %>
      </body>
    </html>
    [root@yinzhengjie ~]# 

    3>.windows的hosts配置信息如下:

    4>.tomcat服务器的配置信息如下

    [root@yinzhengjie ~]# cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    
    
    172.30.1.101 s101
    172.30.1.101 www.yinzhengjie.org.cn
    172.30.1.102 s102
    172.30.1.103 s103
    172.30.1.104 s104
    172.30.1.105 s105
    [root@yinzhengjie ~]# 

    二.编辑Server.xml配置文件

     1>.备份配置文件

    [root@yinzhengjie ~]# cp /usr/local/tomcat/conf/server.xml /usr/local/tomcat/conf/server.xml.bak
    [root@yinzhengjie ~]# 

    2>.编辑Server.xml配置文件,添加虚拟主机信息

          <Host name="www.yinzhengjie.org.cn"  appBase="/home/yinzhengjie/data/www/webapps" unpackWARs="true" autoDeploy="true">
            <context path="" docBase="ROOT" reloadable="true" />
            <context path="/test" docBase="test" reloadable="true" />
    
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="yinzhengjie.org.cn_access_log" suffix=".log"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    
          </Host>

    3>.重启tomcat服务

    [root@yinzhengjie ~]# catalina.sh stop
    Using CATALINA_BASE:   /usr/local/tomcat
    Using CATALINA_HOME:   /usr/local/tomcat
    Using CATALINA_TMPDIR: /usr/local/tomcat/temp
    Using JRE_HOME:        /soft/jdk
    Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
    [root@yinzhengjie ~]# 
    [root@yinzhengjie ~]# 
    [root@yinzhengjie ~]# catalina.sh start
    Using CATALINA_BASE:   /usr/local/tomcat
    Using CATALINA_HOME:   /usr/local/tomcat
    Using CATALINA_TMPDIR: /usr/local/tomcat/temp
    Using JRE_HOME:        /soft/jdk
    Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
    Tomcat started.
    [root@yinzhengjie ~]# 
    [root@yinzhengjie ~]# 

    4>.查看webUI信息如下

    5>.查看test页面

  • 相关阅读:
    cf------(round)#1 C. Ancient Berland Circus(几何)
    cf------(round)#1 B. Spreadsheets(模拟)
    grep 精确匹配
    解决 service iptables save 报错 please try to use systemctl
    kubernetes 亲和性调度详解
    免费好用的SSH手机客户端
    axios和drf结合的增删改查
    CDH 部署 Hadoop:5.开始安装
    OpenNebula概述
    Python 3.x 引入了函数注释
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/9515210.html
Copyright © 2011-2022 走看看