Linux七大项目作业——HTTPD

HTTPD
1、根据自己的环境配置任意IP地址,但IP地址最后一段为自己的学号。
2、配置DNS服务器,要求添加两个区域“dayXX.net”和“nightXX.net”;
建立www. dayXX.net和www.nightXX.net地址记录指向本机IP。
3、使用apache来建立2个基于域名的虚拟主机站点:www.dayXX.net和www.nightXX.net,
根据配置的DNS服务,网站主目录分别是/html/dayXX和html/nightXX。
4.建立主页: www.dayXX.net主页内容为“this is dayXX.net’s web page”; www.nightXX.net主页内容为“this is nightXX.net’s web page”;
5、在WIN7用IE浏览器测试。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
rpm -q httpd    //检查是否安装HTTPD
yum -y install httpd //安装HTTPD服务
systemctl restart httpd //重启HTTPD服务,这里要等待一回
systemctl stop firewalld //关闭防火墙
curl 172.16.118.118

//下面是配置DNS服务器,添加两个区域,如果前面或者上课做过了的可以不用做
vi /etc/named.conf
两个any


vi /etc/named.rfc1912.zones //改主配置文件,添加day18.net和night18.net

zone "day18.net." IN {
type master;
file "day18.net.zone";
allow-update { none; };
};

zone "night18.net." IN {
type master;
file "night18.net.zone";
allow-update { none; };
};

cd /var/named
cp -p named.localhost day18.net.zone
vi day18.net.zone
@ NS dns.day18.net.
dns A 172.16.118.118
www A 172.16.118.118
cp -p day18.net.zone night18.net.zone
vi night18.net.zone
@ NS dns.night18.net.
dns A 172.16.118.118
www A 172.16.118.118

systemctl restart named
systemctl stop firewalld

//nslookup 测试
[root@lai18 ~]# nslookup
> www.day18.net //输入
Server: 127.0.0.1
Address: 127.0.0.1#53

Name: www.day18.net
Address: 172.16.118.118
> www.night18.net //输入
Server: 127.0.0.1
Address: 127.0.0.1#53

Name: www.night18.net
Address: 172.16.118.118
> //输入exit退出

//下面是使用apache来建立2个基于域名的虚拟主机站点 和建立主页
cd /var/www/html/
mkdir day18
vi day18/index.html
this is day18.net's web page //写入的内容
mkdir night18
vi night18/index.html
this is night18.net's web page //写入的内容
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak //备份httpd.conf
vi /etc/httpd/conf/httpd.conf
#ServerName www.example.com:80 //把#去掉,www.example.com改为自己的IP地址,如下
#ServerName 172.16.118.118:80
//再添加如下内容
<VirtualHost 172.16.118.118>
DocumentRoot /var/www/html/day18
ServerName www.day18.net
</VirtualHost>
<VirtualHost 172.16.118.118>
DocumentRoot /var/www/html/night18
ServerName www.night18.net
</VirtualHost>

systemctl restart httpd //重启HTTPD服务,这里要等待一回

//测试
在win7中输入www.day18.net和www.night18.net测试
在Linux中测试输入 curl 172.16.118.118
[root@lai18 html]# curl 172.16.118.118
this is day18.net's web page

改主配置文件
day18.net
night18.net
nslookup测试
apache来建立2个基于域名的虚拟主机站点 和建立主页
在这里插入图片描述
测试