一、实验目标
1.掌握Linux系统中Apache服务器的安装与配置;
2.掌握个人主页、虚拟目录、基于用户和主机的访问控制及虚拟主机的实现方法。
二、实验要求
练习使用linux系统下WEB服务器的配置方法。
三、实验背景
重庆工程学院为筹备"重庆工程大学"特申请了cqie顶级域名,并将为每个员工开通个人网页服务,为教师和学生间建立沟通的平台,域名为www.姓名拼音字头.cqie,以巫正中为例,域名为www.wzz.cqie,网络拓扑图如下:
图7- 1
每个人的个人主页要实现如下功能:
(1)网页文件上传完成后,立即发布,URL为http://www.wzz.cqie/\~用户名;
(2)在web服务器中建立一个名为private的虚拟目录,其对应的物理路径是/data/private。并配置Web服务器对虚拟目录启用用户认证,只允许yun90用户访问。
(3)在web服务器中建立一个名为test的虚拟目录,其对应的物理路径是/dir1/test,并配置web服务器仅允许来自网络wzz.cqie域和192.168.100.0/24网段的客户机访问该虚拟目录。
(4)使用192.168.100.172和192.168.100.173两个IP地址,创建基于IP地址的虚拟主机。其中192.168.100.172的虚拟主机对应的主目录为/var/www/ip2,192.168.100.173的虚拟主机对应的主目录为/var/www/ip3。
(5)创建基于www1.wzz.cqie和www2.wzz.cqie两个虚拟域名的虚拟主机,域名为www1.wzz.cqie虚拟主机对应的目录为/var/www/wzz1,www2.wzz.cqie虚拟主机对应的目录为/var/www/wzz2。
(6)要求网站目录要部署在nfs存储服务器提供的存储空间上。
四、实验原理/流程
实验先决条件:DNS服务器、WEB服务器、NFS服务器连接客户端四台虚拟机内网(192.168.100.0/24)连通,并通过NAT与互联网连接。
图7- 2
回顾步骤1:nfs服务器准备网络存储
0.1.1 在nfs存储服务器上添加磁盘
图7- 3
图7- 4
重启系统 reboot ,查看
|---------------------------------------------------------------------------------------------|
| [root@nfs ~]# lsblk ...... sdb 8:16 0 1G 0 disk sr0 11:0 1 1024M 0 rom |
0.1.2安装工具
|----------------------------------------------------------------------------------------|
| //nfs 服务器端 #yum install -y mdadm nfs-utils.x86_64 rpcbind.x86_64 net-tools |
0.1.3 分区、格式化并挂载
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@nfs ~]# fdisk /dev/sdb2 ...... 命令 ( 输入 m 获取帮助 ) : n 分区类型 p 主分区 (0 个主分区, 0 个扩展分区, 4 空闲 ) e 扩展分区 ( 逻辑分区容器 ) 选择 ( 默认 p) : 将使用默认回应 p 。 分区号 (1-4, 默认 1): 第一个扇区 (2048-209715199, 默认 2048): 上个扇区, +sectors 或 +size{K,M,G,T,P} (2048-209715199, 默认 209715199): +1G ...... [root@nfs ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 99G 0 disk ├ ─ sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 98G 0 part ├ ─ cl-root 253:0 0 61.2G 0 lvm / ├ ─ cl-swap 253:1 0 6.9G 0 lvm [SWAP] └─cl-home 253:2 0 29.9G 0 lvm /home sdb 8:16 0 100G 0 disk └─sdb2 8:17 0 1G 0 part sr0 11:0 1 1024M 0 rom |
格式化
|--------------------------------------------------------|
| [root@nfs ~]# mkfs.xfs /dev/sdb1 ...... |
永久挂载 ( 先创建 /mnt/sdb2 目录 )
|-----------------------------------------------------------------------------------------------|
| [root@nfs ~]# vi /etc/fstab // 最后一行添加 /dev/sdb2 /mnt/sdb2 xfs defaults 0 0 |
安装并查看
|-------------------------------------------------------------------------------------------------------------|
| [root@nfs ~]# mount -a [root@nfs ~]# df -Th ...... /dev/sdb1 xfs 40G 318M 40G 1% /mnt |
开机启动nfs/rpcbind服务
|-------------------------------------------------------------------------------------------------------------------|
| [root@nfs ~]# systemctl enable nfs-server.service ...... [root@nfs ~]# systemctl enable rpcbind |
0.1.4 NFS 存储服务器共享存储空间
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@nfs ~]# systemctl enable nfs-server.service [root@nfs ~]# systemctl enable rpcbind [root@nfs ~]# vi /etc/exports /mnt/sdb2 192.168.100.0/24(rw,sync,no_root_squash) // 网络共享出去 [root@nfs ~]# systemctl start nfs-server.service [root@nfs ~]# systemctl start rpcbind |
查看
|-----------------------------------------------|
| [root@nfs ~]# netstat -antp| grep rpc |
0.1.5 关闭防火墙并查看共享网络
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@nfs ~]# systemctl stop firewalld.service [root@nfs ~]# setenforce 0 [root@nfs ~]# showmount -e Export list for nfs: /mnt/sdb2 192.168.100.0/24 |
0.1.5 安装应用以验证
|----------------------------------------------------------------------------------------------------------|
| [root@www ~]# yum -y install httpd [root@www ~]# yum install -y nfs-utils.x86_64 net-tools |
0.1.6 (web 服务器 ) 客户端上挂载共享卷(如果没有 /var/www/html 就自行创建)
临时挂载
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@www ~]# mount 192.168.100.69:/mnt/sdb2 /var/www/html [root@www ~]# df -Th 文件系统 类型 容量 已用 可用 已用 % 挂载点 ...... 192.168.100.69:/mnt/sdb2 nfs4 40G 318M 40G 1% /var/www/html |
永久挂载
|-------------------------------------------------------------------------------------------------------------------|
| [root@www ~]# vi /etc/fstab ...... 192.168.100.69:/mnt/sdb2 /var/www/html nfs defaults,_netdev 0 0 |
挂载并查看
|------------------------------------------------------------------------------------------------------------|
| [root@nfs ~]# mount -a [root@www ~]# df -Th ...... /dev/sdb2 nfs 1G 39M 909M 1% /mnt |
回顾步骤2:DNS服务器准备
0.2.1 在DNS服务器上安装工具
|----------------------------------------|
| yum install -y bind bind-utils dnsmasq |
0.2.2 DNS初始配置
一)修改全局配置文件/etc/named.conf
说明:养成良好的习惯,在修改任何配置文件前,先进行备份,然后再修改
|---------------------------------------------------------------------------------------------|
| [root@DNS ~]# cp /etc/named.conf /etc/named.conf.bak [root@DNS ~]# vi /etc/named.conf |
a. 将"BIND侦听的DNS查询请求本机IP地址127.0.0.1修改为任一主机any,端口53不变指定接收DNS查询请求的客户端也修改为任一any:如下所示:
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ...... options { listen-on port 53 { any; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; secroots-file "/var/named/data/named.secroots"; recursing-file "/var/named/data/named.recursing"; allow-query { any; }; ...... |
b. 继续修改dnssec-validation no;(设置为yes则需关闭 SElinux(linux安全增强特性),改为no可以忽略SELinux影响。)
|-----------------------------------------------------------------------|
| ...... recursion yes; dnssec-enable yes; dnssec-validation no; ...... |
c. 根区域文件保持不变(13个根域服务不能动,根域文件名为named.ca)
|----------------------------------------------|
| zone "." IN { type hint; file "named.ca"; }; |
d. 将主配置文件目录改成/etc/named.zone,原文件/etc/named.rfc1912.zones。最后保存退出。
二)修改主配置文件 (用于指定正向、反向的区域名等信息)
a.将/etc/named.rfc1912.zones复制为全局配置文件中指定的主配置文件/etc/named.zones)
|------------------------------------------------------------------|
| [root@DNS ~]# cp -p /etc/named.rfc1912.zones /etc/named.zones |
说明:-p 参数是复制是保留原文件的属性,拥有者及所属的组不变。
b.修改主配置文件vi /etc/named.zones,在最后编辑增加以下内容,最后保存退出。
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ...... zone "wzz.cqie" IN { type master; file "wzz.cqie.zone"; allow-update { none; }; }; zone "100.168.192.in-addr.arpa" IN { type master; file "100.168.192.zone"; allow-update { none; }; }; |
三)修改正、反向解析区域申明文件
a.进入区域配置文件目录,并查看该目录下的文件,包含根域文件named.ca
b.复制named.localhost 为正向解析区域文件wzz.cqie.zone
养成良好的习惯:不要在样板上直接修改。
|--------------------------------------------------------------------------------------------------|
| [root@DNS ~]# cd /var/named [root@DNS ~ named]#cp -p named.localhost wzz.cqie.zone |
c.编辑正向区域文件wzz.cqie.zone
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| $TTL 1D @ IN SOA @ root.wzz.cqie. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum @ IN NS dns.wzz.cqie. @ IN MX 10 mail.wzz.cqie. dns A 192.168.100.66 ...... ftp A 192.168.100.68 nfs A 192.168.100.69 samba A 192.168.100.70 www A 192.168.100.71 web CNAME www.wzz.cqie mail A 192.168.100.72 ...... |
d. 复制named.loopback 为反向解析区域文件100.168.192.zone
e. 编辑反向区域文件100.168.192.zone
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ root@DNS named]# cp -p named.loopback 100.168.192.zone [root@DNS named]# vi 100.168.192.zone $TTL 1D @ IN SOA @ root.wzz.cqie. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum @ IN NS dns.wzz.cqie. @ IN MX 10 mail.wzz.cqie. 66 PTR dns.wzz.cqie. ...... 68 PTR ftp.wzz.cqie. 69 PTR nfs.wzz.cqie. 70 PTR samba.wzz.cqie. 71 PTR www.wzz.cqie. 72 PTR mail.wzz.cqie. ...... |
四)配置防火墙,允许DNS服务通过,重新加载防火墙(如果firewall开启)
|--------------------------------------------------------------------------------------------------------------------|
| [root@DNS ~]# firewall-cmd --permanent --add-service=dns success [root@DNS ~]# firewall-cmd --reload success |
五)启动DNS服务,系统启动自动加载DNS服务
|--------------------------------------------------------------------------------|
| [root@DNS ~]# systemctl start named [root@DNS ~]# systemctl enable named |
六)验证(此处验证www、nfs、dns三台主机域名)
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@www www]# ping www.wzz.cqie -c 1 PING www.wzz.cqie (192.168.100.71) 56(84) bytes of data. 64 bytes from www.wzz.cqie (192.168.100.71): icmp_seq=1 ttl=64 time=0.025 ms --- www.wzz.cqie ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.025/0.025/0.025/0.000 ms [root@www www]# ping dns.wzz.cqie -c 1 PING dns.wzz.cqie (192.168.100.66) 56(84) bytes of data. 64 bytes from dns.wzz.cqie (192.168.100.66): icmp_seq=1 ttl=64 time=0.270 ms --- dns.wzz.cqie ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.270/0.270/0.270/0.000 ms [root@www www]# ping nfs.wzz.cqie -c 1 PING nfs.wzz.cqie (192.168.100.69) 56(84) bytes of data. 64 bytes from nfs.wzz.cqie (192.168.100.69): icmp_seq=1 ttl=64 time=0.252 ms --- nfs.wzz.cqie ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.252/0.252/0.252/0.000 ms |
步骤1:给web服务器内网卡(我的机器是ens37)再添加两个内网(192.168.100.0/24)IP
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@www www]# ip addr add 192.168.100.172/24 dev ens37 [root@www www]# ip addr add 192.168.100.173/24 dev ens37 [root@www www]# ip a ...... 4: ens37: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:50:56:37:98:a7 brd ff:ff:ff:ff:ff:ff inet 192.168.100.71/24 brd 192.168.100.255 scope global noprefixroute ens37 valid_lft forever preferred_lft forever inet 192.168.100.172/24 scope global secondary ens37 valid_lft forever preferred_lft forever inet 192.168.100.173/24 scope global secondary ens37 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe37:98a7/64 scope link noprefixroute valid_lft forever preferred_lft forever ...... |
步骤2:为了满足功能(5),编辑正向区域文件cd /var/named,将www1和www2添加到
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| $TTL 1D @ IN SOA @ root.wzz.cqie. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum @ IN NS dns.wzz.cqie. @ IN MX 10 mail.wzz.cqie. dns A 192.168.100.66 dns1 A 192.168.100.67 ftp A 192.168.100.68 nfs A 192.168.100.69 samba A 192.168.100.70 www A 192.168.100.71 www1 A 192.168.100.172 www2 A 192.168.100.173 web CNAME www.wzz.cqie mail A 192.168.100.72 squid A 192.168.100.73 |
重启named服务
|------------------------------|
| []#systemctl restart named |
测试
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@DNS named]# ping www1.wzz.cqie -c 1 PING www1.wzz.cqie (192.168.100.172) 56(84) bytes of data. 64 bytes from 192.168.100.172 (192.168.100.172): icmp_seq=1 ttl=64 time=0.443 ms --- www1.wzz.cqie ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.443/0.443/0.443/0.000 ms [root@DNS named]# ping www2.wzz.cqie -c 1 PING www2.wzz.cqie (192.168.100.173) 56(84) bytes of data. 64 bytes from 192.168.100.173 (192.168.100.173): icmp_seq=1 ttl=64 time=0.586 ms --- www2.wzz.cqie ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.586/0.586/0.586/0.000 ms |
步骤3:开通个人主页
|----------------------------------------------------------------------------------------------------------------|
| [root@www www]# cd /etc/httpd/conf.d [root@www conf.d]# ls autoindex.conf README userdir.conf welcome.conf |
a.设置用户首页地址文件userdir.conf(红色的为模板变动除)
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@www conf.d]# vi userdir.conf ...... <IfModule mod_userdir.c> ...... # UserDir disabled #...... UserDir public_html </IfModule> # # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. # <Directory "/home/*/public_html"> AllowOverride FileInfo AuthConfig Limit Indexes Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS </Directory> |
保存退出,重启服务
|----------------------------------------------|
| [root@www conf.d]# systemctl restart httpd |
b.新建harry用户,创建public_html目录,在该目录下创建html
|---|
| |
保存退出。
|---------------------------------------------------------------|
| [root@www harry]# cd .. [root@www home]# chmod o+x harry/ |
到客户端打开:
图7- 5
我好好的头像,被浏览器搞得乱七八糟的☹
功能(1)到此,已经完成。
**************************************************************************************
步骤4:虚拟目录用户认证
web服务器中建立一个名为private的虚拟目录,其对应的物理路径是/data/private。并配置Web服务器对虚拟目录启用用户认证,只允许yun90用户访问。
配置httpd
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| []# vi /etc/httpd/conf/httpd.conf ...... # # Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory> ...... |
复制上面带底色部分代码,紧挨着粘贴到下面,并修改
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ...... # # Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory> Alias /private /data/private <Directory "/data/private"> AllowOverride None AuthType Basic AuthName "请输入用户姓名:" AuthUserFile /etc/httpd/conf/.htpasswd Require valid-user </Directory> ...... |
安装htpasswd
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@www home]# yum install httpd-devel.x86_64 -y ...... 完毕! [root@www home]# htpasswd -c /etc/httpd/conf/.htpasswd yun90 New password: Re-type new password: Adding password for user yun90 |
查看一下:
|----------------------------------------------------------------------------------------------|
| [root@www home]# cat /etc/httpd/conf/.htpasswd yun90:apr1ktPXvXj3$3m41frZuIpsLf3iDCHDxk0 |
重启
|-------------------------------------------------------------------------------|
| [root@www home]# chmod o+x /data [root@www home]# systemctl restart httpd |
图7- 6
图7- 7
至此,完成了虚拟目录的用户认证设置。
步骤5:放过特定域名和IP地址的客户端访问虚拟目录
在web服务器中建立一个名为test的虚拟目录,其对应的物理路径是/dir1/test,并配置web服务器仅允许来自网络wzz.cqie域和192.168.100.0/27网段的客户机访问该虚拟目录。
a. 在/etc/httpd/conf/httpd.conf添加下面部分内容
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@www home]# vi /etc/httpd/conf/httpd.conf ...... Alias /test /dir1/test <Directory "/dir1/test"> AllowOverride None Require all granted Order allow,deny Allow from wzz.cqie Allow from 192.168.100.0/27 </Directory> ...... |
b.在/dir1/test下创建index.html,修改默认文件的权限
|--------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@www home]# mkdir -p /dir1/test [root@www home]#vi /dir1/test/index.html 我是test,等的就是你! [root@www ~]# chmod o+x /dir1/test/index.html |
重启httpd
|--------------------------------------------|
| [root@www home]# systemctl restart httpd |
我在192.168.100.100的客户端访问
图7- 8
改变ip地址为192.168.100.25再试:
图7- 9
刷新ip
图7- 10
图7- 11
在dns.wzz.cqie(192.168.100.66)上访问:
|----------------------------------------------------------------------|
| [root@DNS ~]# wget -O - -q http://www.wzz.cqie/test 我是test,等的就是你! |
Gosh!
可见,当地址范围不在192.168.100.0/27范围内的客户端,且不是wzz.cqie域里面的用户无法访问test,192.168.100.66虽然不在192.168.100.0/27内,但是它是wzz.cqie域内用户,也能访问。
步骤6:创建基于IP地址的虚拟主机
使用192.168.100.172和192.168.100.173两个IP地址,创建基于IP地址的虚拟主机。其中192.168.100.172的虚拟主机对应的主目录为/var/www/ip2,192.168.100.173的虚拟主机对应的主目录为/var/www/ip3。
a.创建虚拟主机。
进入/etc/httpd/conf.d目录创建vhost.conf文件
|--------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@www ~]# cd /etc/httpd/conf.d [root@www conf.d]# ls autoindex.conf README userdir.conf welcome.conf [root@www conf.d]# vi vhost.conf |
创建两个基于ip地址的虚拟主机
|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| <VirtualHost 192.168.100.172> DocumentRoot /var/www/ip2 </VirtualHost> <VirtualHost 192.168.100.173> DocumentRoot /var/www/ip3 </VirtualHost> |
c.创建虚拟主机数据目录及文件
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@www conf.d]# mkdir -p /var/www/ip2 [root@www conf.d]# mkdir -p /var/www/ip3 [root@www conf.d]# cd /var/www/ip2 [root@www ip2]# vi index.html [root@www ip2]# cd .. [root@www www]# cd ip3 [root@www ip3]# vi index.html |
两个index.html的内容是:
|---------------------------------------------------------------------------------------------------------------|
| [root@www ip3]# cat index.html 我是192.168.100.173的主页! [root@www ip3]# cat index.html 我是192.168.100.173的主页! |
重启httpd
|------------------------------------------|
| [root@www ip3]#systemctl restart httpd |
d.验证
Linux上验证
|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@DNS ~]# wget -O - -q http://192.168.100.172 我是192.168.100.172的主页! [root@DNS ~]# wget -O - -q http://192.168.100.173 我是192.168.100.173的主页! |
Windows下验证
图7- 12
至此,完成了任务(4)基于IP的虚拟主机的部署。
步骤7:创建基于虚拟域名的虚拟主机
a.虚拟主机数据目录创建
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@www conf.d]# mkdir -p /var/www/wzz1 [root@www conf.d]# mkdir -p /var/www/wzz2 [root@www conf.d]# vi /var/www/wzz1/index.html [root@www conf.d]# vi /var/www/wzz2/index.html |
index.html内容为
|--------------------------------|
| I'm homepage of www1.wzz.cqie. |
b.在虚拟主机配置文件中vhost.conf文件,添加虚拟主机(红色部分为指定的基于虚拟域名的虚拟主机)
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| <VirtualHost 192.168.100.172> DocumentRoot /var/www/ip2 </VirtualHost> <VirtualHost 192.168.100.173> DocumentRoot /var/www/ip3 </VirtualHost> <VirtualHost 192.168.100.172> DocumentRoot /var/www/wzz1 ServerName www1.wzz.cqie </VirtualHost> <VirtualHost 192.168.100.173> DocumentRoot /var/www/wzz2 ServerName www2.wzz.cqie </VirtualHost> |
保存退出并重启httpd
|--------------------------------------|
| [root@www]#systemctl restart httpd |
c.验证
Linux下验证
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [root@DNS ~]# wget -O - -q http://www1.wzz.cqie I'm homepage of www1.wzz.cqie. [root@DNS ~]# wget -O - -q http://www2.wzz.cqie I'm homepage of www2.wzz.cqie. |
Windows下验证
图7- 13
至此,完成了任务(5)。