Web 服务应用 -- Tomcat 动态站点 & 虚拟主机

Tomcat 动态站点 & 虚拟主机

一、动态站点

准备数据库

[root@node05 ~]# yum install mariadb-server -y
[root@node05 ~]# systemctl enable --now mariadb
[root@node05 ~]# mysql 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database jpress default character set utf8;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on jpress.* to jpress@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> 

部署 jpress

[root@node05 webapps]# ll
total 20316
drwxr-x--- 14 root root     4096 Mar  7 08:33 docs
drwxr-x---  6 root root       83 Mar  7 08:33 examples
drwxr-x---  5 root root       87 Mar  7 08:33 host-manager
drwxr-x---  7 root root      102 Mar  7 16:06 jpress-web-newest
-rw-r--r--  1 root root 20797013 Aug  9  2020 jpress-web-newest.war
drwxr-x---  5 root root      103 Mar  7 08:33 manager
drwxr-x---  3 root root      306 Mar  7 08:33 ROOT

上传压缩包,自动解压到当前路径!*

浏览器登录:http://192.168.5.15:8080/jpress-web-newest

单机下一步,继续
在这里插入图片描述
配置数据库信息
在这里插入图片描述
设置管理员密码
在这里插入图片描述
等待安装 jpress
在这里插入图片描述
部署完成
在这里插入图片描述

二、虚拟主机

修改 Tomcat 配置文件

[root@node05 ~]# cd /usr/local/tomcat/conf/
[root@node05 conf]# cp server.xml{,.bak}
[root@node05 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 &quot;%r&quot; %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 &quot;%r&quot; %s %b" />
        </Host>



[root@node05 conf]# mkdir -p /web/{a,b}
[root@node05 conf]# vim /web/a/index.jsp
<html>
        <head>
        <title>JSP a page</title>
        </head>
        <body>
            <% out.println("Welocome to test site,http://www.a.com");%>
        </body>
</html>


[root@node05 conf]# vim /web/b/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
        <head>
        <title>JSP b page</title>
        </head>
        <body>
            <% out.println("Welocome to test site,http://www.b.com");%>
        </body>
</html>

[root@node05 conf]# systemctl restart tomcat.service

添加hosts解析
在这里插入图片描述
浏览器访问:http://www.a.com:8080/
在这里插入图片描述
浏览器访问:http://www.b.com:8080/
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值