一:实验目的
项目考核信息网站部署完毕后,公司人力资源部计划部署一个员工考勤网站。因此管理员需要在一台服务器上部署多个站点,为了方便今后公司内部网站的部署和管理,管理员可以采用基于域名的虚拟主机或基于IP地址的虚拟主机两种方法来配置多个站点。在实施过程中除了要部署员工考勤网站之外还要对项目考核信息发布网站进行重新部署
为了方便对网站的访问,分别为两个网站设置本地域名:www.dsch.com和www.dhjg.com,站点根目录:/var/www/html/dsch和/var/www/html/dhjg,首页位根目录下的index.html页面
二:安装
apr.x86_64 0:1.4.8-5.el7 apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-90.el7.centos mailcap.noarch 0:2.1.41-2.el7
完毕!
[root@localhost ~]# systemctl stsrt httpd.service
Unknown operation 'stsrt'.
[root@localhost ~]# systemctl ststus httpd.service
Unknown operation 'ststus'.
[root@localhost ~]# systemctl start httpd.service
[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since 一 2024-04-22 18:50:56 CST; 22s ago
Docs: man:httpd(8)
三:创建两个虚拟网站
[root@localhost ~]# mkdir /var/www/html/dhsc
[root@localhost ~]# mkdir /var/www/html/dhjg
[root@localhost ~]# vim /var/www/html/dhsc/dhsc.html
[root@localhost ~]# vim /var/www/html/dhsc/dhjg.html
四:域名注册,在/etc/hosts 追加一行
192.168.159.132 www.dhsc.com www.dhjg.com
[root@localhost ~]# vim /etc/hosts
验证
[root@localhost ~]# ping www.dhsc.com
PING www.dhsc.com (192.168.159.132) 56(84) bytes of data.
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=1 ttl=64 time=0.061 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=2 ttl=64 time=0.086 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=3 ttl=64 time=0.087 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=4 ttl=64 time=0.041 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=5 ttl=64 time=0.040 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=6 ttl=64 time=0.084 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=7 ttl=64 time=0.041 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=8 ttl=64 time=0.050 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=9 ttl=64 time=0.048 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=10 ttl=64 time=0.086 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=11 ttl=64 time=0.082 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=12 ttl=64 time=0.084 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=13 ttl=64 time=0.086 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=14 ttl=64 time=0.038 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=15 ttl=64 time=0.085 ms
^C
--- www.dhsc.com ping statistics ---
15 packets transmitted, 15 received, 0% packet loss, time 14002ms
rtt min/avg/max/mdev = 0.038/0.066/0.087/0.022 ms
[root@localhost ~]# ping www.dhjg.com
PING www.dhsc.com (192.168.159.132) 56(84) bytes of data.
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=1 ttl=64 time=0.036 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=2 ttl=64 time=0.086 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=3 ttl=64 time=0.058 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=4 ttl=64 time=0.050 ms
64 bytes from www.dhsc.com (192.168.159.132): icmp_seq=5 ttl=64 time=0.084 ms
^C
--- www.dhsc.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 0.036/0.062/0.086/0.021 ms
[root@localhost ~]#
五
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#
#
# EnableMMAP and EnableSendfile: On systems that support it,
# memory-mapping or the sendfile syscall may be used to deliver
# files. This usually improves server performance, but must
# be turned off when serving from networked-mounted
# filesystems or if support for these functions is otherwise
# broken on your system.
# Defaults if commented: EnableMMAP On, EnableSendfile Off
#
#EnableMMAP off
EnableSendfile on
# Supplemental configuration
#
# Load config files in the "/etc/httpd/conf.d" directory, if any.
IncludeOptional conf.d/*.conf
Include conf/vhost/*.conf
六:创建第一个域名
[root@localhost ~]# mkdir /etc/httpd/conf/vhost
[root@localhost ~]# vim /etc/httpd/conf/vhost/dhsc.conf
[root@localhost ~]# vim /etc/httpd/conf/vhost/dhsc.conf
[root@localhost ~]#
七;