综合练习: 请给openlab搭建web网站,网站需求:
1、基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
2、给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料www.openlab.com/money. 网站访问缴费网站
3、要求
(1) 学生信息网站只有song和tian两人可以访问,其他用户不能访问。
(2) 访问缴费网站实现数据加密基于https访问。
一、需求1
1、安装Apache
[root@server ~]# yum install httpd -y
2、预处理
[root@server ~]# setenforce 0 # 临时关闭
[root@server ~]# systemctl stop firewalld # 关闭防火墙
[root@server ~]# systemctl disable firewalld # 关闭开机启动
[root@server ~]# systemctl start httpd # 启动httpd服务
[root@server ~]# systemctl enable httpd # 设置httpd开机启动
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@server ~]# systemctl status httpd #查看状态
3、 新建目录
4、写入网页显示内容
[root@server ~]# echo 'welcome to openlab!!!' > /www/openlab/index.html
5、手动配置IP地址与域名的映射关系,使用本地hosts配置文件实现
#Linux端
# windows端,打开C:\Windows\System32\drivers\etc\hosts,添加以下内容:
192.168.132.132 www.openlab.com
6、主配置文件设置:
[root@server ~]# vim /etc/httpd/conf/httpd.conf #打开主配置文件,在最后加入下列内容:
7、重启服务并测试
[root@server ~]# systemctl restart httpd
在默认浏览器使用域名<=>IP地址测试
二、需求2
1、创建一个student、data、money目录
[root@server ~]# mkdir /www/openlab/student
[root@server ~]# mkdir /www/openlab/data
[root@server ~]# mkdir /www/openlab/money
2、写入student、data、money网页内容
[root@server ~]# echo 'This is student' > /www/openlab/student/index.html
[root@server ~]# echo 'This is data' > /www/openlab/data/index.html
[root@server ~]# echo 'This is money' > /www/openlab/money/index.html
3、设置访问权限
[root@server ~]# chmod -Rf 755 /www/openlab/student
[root@server ~]# chmod -Rf 755 /www/openlab/data
[root@server ~]# chmod -Rf 755 /www/openlab/money
4、设置主配置文件,配置如下:
5、重启服务
[root@server ~]# systemctl restart httpd
6、测试
三、需求3
1、学生信息网站只有song和tian两人可以访问,其他用户不能访问。
(1)首先添加新用户
[root@server student]# useradd song
[root@server student]# passwd song
[root@server student]# useradd tian
[root@server student]# passwd tian
(2)访问缴费网站实现数据加密基于https访问。
[root@server student]# htpasswd -c /etc/httpd/passwd song
[root@server student]# htpasswd /etc/httpd/passwd tian
(3)主配置文件设置
(4)重启服务
[root@server student]# systemctl restart httpd
(5)测试![](https://img-blog.csdnimg.cn/3f1b31b56129476e9b2158d3350e091d.png)
2、访问缴费网站实现数据加密基于https访问。
(1)首先安装mod_ssl组件
[root@server ~]# yum install mod_ssl -y
(2)在/etc/pki/tls/private中生成私钥文件
(3)在/etc/pli/tls/certs目录中新建数字证书: cd /etc/pki/tls/certs
(4) 修改配置文件:
[root@server ~]# vim /etc/httpd/conf.d/ssl.conf
(5)重启服务
[root@server ~]# systemctl restart httpd
(6)测试
点击“高级”,查看证书