一.实验要求
综合练习:请给openlab搭建web网站
网站需求:
1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于[www.openlab.com/student](http://www.openlab.com/student) 网站访问学生信息,[www.openlab.com/data](http://www.openlab.com/data)网站访问教学资料[www.openlab.com/money网站访问缴费网站](http://www.openlab.com/money网站访问缴费网站)。
3.要求
(1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
(2)访问缴费网站实现数据加密基于https访问。
二.实验过程
1. 基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!
客户端配置
[root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# vim base.repo [base] name=base baseurl=file:///mnt/BaseOS gpgcheck=0 [app] name=appstream baseurl=file:///mnt/AppStream gpgcheck=0 #添加配置文件,安装存储库 [root@localhost pl]# yum install httpd -y #安装服务器软件 [root@localhost ~]# vim /etc/hosts #在hosts文件中添加IP及域名用于域名解析 192.168.126.134 www.openlab.com
服务端配置
在服务端配置网站页面 [root@localhost conf.d]# mkdir /www/openlab #在www下创建openlab [root@localhost conf.d]# echo "welcome to openlab!!!" > /www/openlab/index.html//在opendlab下的index.html中写下网页内容 [root@localhost conf.d]# vim openlab.conf 2 <VirtualHost 192.168.126.134:80> 3 DocumentRoot /www/openlab 4 ServerName www.openlab.com 5 ErrorLog "/var/log/httpd/134-error_log" 6 CustomLog "/var/log/httpd/134-access_log" common 7 </VirtualHost> 8 <directory /www/openlab> 9 AllowOverride None 10 Require all granted 11 </directory> #修改网页的配置文件 [root@localhost conf.d]# setenforce 0 #设置为宽容模式 [root@localhost conf.d]# systemctl status firewalld #查看防火墙是否关闭
客户端访问结果
[root@localhost ~]# curl www.openlab.com welcome to openlab!!! #成功使用域名访问
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于[www.openlab.com/student](http://www.openlab.com/student) 网站访问学生信息,[www.openlab.com/data](http://www.openlab.com/data)网站访问教学资料[www.openlab.com/money网站访问缴费网站](http://www.openlab.com/money网站访问缴费网站)。
服务端
[root@localhost conf.d]# mkdir /www/openlab/{student,data,money} #创建子界面目录 [root@localhost conf.d]# echo "这是学生信息" > /www/openlab/student/index.html [root@localhost conf.d]# echo "这是教学资料" > /www/openlab/data/index.html [root@localhost conf.d]# echo "这是缴费网站" > /www/openlab/money/index.html #写下网页信息 [root@localhost conf.d]# vim openlab.conf #修改配置文件 8 <VirtualHost 192.168.126.134:80> 9 DocumentRoot /www/openlab/student 10 ServerName www.openlab.com/student 11 ErrorLog "/var/log/httpd/student-error_log" 12 CustomLog "/var/log/httpd/student-access_log" common 13 </VirtualHost> 14 <VirtualHost 192.168.126.134:80> 15 DocumentRoot /www/openlab/data 16 ServerName www.openlab.com/data 17 ErrorLog "/var/log/httpd/data-error_log" 18 CustomLog "/var/log/httpd/data-access_log" common 19 </VirtualHost> 20 <VirtualHost 192.168.126.134:80> 21 DocumentRoot /www/openlab/money 22 ServerName www.openlab.com/money 23 ErrorLog "/var/log/httpd/money-error_log" 24 CustomLog "/var/log/httpd/money-access_log" common 25 </VirtualHost> 26 [root@localhost conf.d]# systemctl restart httpd
客户端访问结果
[root@localhost ~]# curl www.openlab.com/student/ 这是学生信息 [root@localhost ~]# curl www.openlab.com/data/ 这是教学资料 [root@localhost ~]# curl www.openlab.com/money/ 这是缴费网站
3.要求
(1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
(2)访问缴费网站实现数据加密基于https访问。(1)服务端配置
[root@localhost ~]# htpasswd -c /etc/httpd/mymima song #创建song用户 New password: Re-type new password: [root@localhost ~]# htpasswd /etc/httpd/mymima tian #此处不再使用-c命令,避免song被覆盖 New password: Re-type new password: [root@localhost conf.d]# vim openlab.conf 31 <directory /www/openlab/student> 32 AllowOverride None 33 authtype basic 34 authname "please login" 35 authuserfile /etc/httpd/mymima 36 require user song tian 37 </directory> 38 //更改配置文件修改用户访问权限 [root@localhost conf.d]# systemctl restart httpd
客户端访问结果
[root@localhost ~]# curl www.openlab.com/student/ -u tian Enter host password for user 'tian': 这是学生信息 [root@localhost ~]# curl www.openlab.com/student/ -u song Enter host password for user 'song': 这是学生信息
(2)服务端配置
#mod_ssl是一种以openssl 的工具箱为基础专门为apache webserver 提供密码保护的软件。 [root@localhost ~]# yum install mod_ssl httpd -y #若无法下载需重新挂载 [root@localhost ~]# vim /etc/httpd/conf.d/openlab.conf 38 <virtualhost 192.168.126.134:443> 39 servername www.openlab.com 40 documentroot /www/openlab/money 41 sslengine on 42 SSLCertificateFile /etc/pki/tls/certs/localhost.crt 43 SSLCertificateKeyFile /etc/pki/tls/private/localhost.key//此处的路径应与证书和秘钥路径相同 44 45 </virtualhost> 46 47 <directory /www/openlab/money> 48 allowoverride none 49 require all granted 50 </directory> [root@localhost ~]# systemctl restart httpd
访问结果