目录
网站需求:
1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站:
- (1)基于 www.openlab.com/student](http://www.openlab.com/student 网站访问学生信息;
- (2)基于 www.openlab.com/data](http://www.openlab.com/data 网站访问教学资料;
- (3)基于 www.openlab.com/money 网站访问缴费网站
3.要求
- (1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。
- (2)访问缴费网站实现数据加密基于https访问。
一、访问openlab网站
1、安装相应的包
已配置好仓库
yum install httpd -y
关闭防火墙
yum install httpd -y
setenforce 0
挂载到本地磁盘
mount /dev/sr0 /mnt/
2、更改配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/vhost.conf
<VirtualHost 192.168.171.132:80>
Servername www.openlab.com
DocumentRoot /www/openlab
</VirtualHost>
<Directory /www/>
AllowOverride none
Require all granted
</Directory>
[root@localhost ~]# mkdir /var/www/openlab //创建对应的文件
[root@localhost ~]# echo welcome to openlab > /var/www/openlab/index.html //手动写入内容
[root@localhost conf.d]# vim /etc/hosts //在客户端修改hosts
[root@localhost conf.d]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.171.132 www.openlab.com
[root@localhost ~]# systemctl restart httpd //重启httpd服务
3、测试是否可以访问
二、3个子界面
1、创建对应的目录wenjian
[root@localhost ~]# mkdir /var/www/openlab/student
[root@localhost ~]# mkdir /var/www/openlab/data
[root@localhost ~]# mkdir /var/www/openlab/money
2、手动输入文件内容
[root@localhost ~]# echo xueshengxixin > /var/www/openlab/student/index.html
[root@localhost ~]# echo jiaoxueziliao >/var/www/openlab/data/index.html
[root@localhost ~]# echo jiaofei >/var/www/openlab/money/index.html
3、查看子网结果
三、指定用户访问和加密访问
1、指定用户访问student
(1)创建song和tian两个用户
[root@localhost ~]# htpasswd -c /etc/httpd/yonghu song
New password:
Re-type new password:
Adding password for user song
[root@localhost ~]# htpasswd -c /etc/httpd/yonghu tian
New password:
Re-type new password:
Adding password for user tian
(2)在配置文件中添加内容
[root@localhost ~]# vim /etc/httpd/conf.d/vhost.conf
[root@localhost ~]# cat /etc/httpd/conf.d/vhost.conf
<VirtualHost 192.168.171.132:80>
Servername www.openlab.com
DocumentRoot /var/www/openlab
</VirtualHost>
<Directory /var/www/openlab>
AllowOverride none
Require all granted
</Directory>
// 新添加的用户信息
<directory /var/www/openlab/student>
allowoverride none
authtype basic
authname "please login"
authuserfile /etc/httpd/yonghu
require user song tian
</directory>
(3)访问student
2、加密访问 money网站
(1)下载mod_ssl 软件包
[root@localhost ~]# yum install mod_ssl
(2)生成私钥文件和证书
[root@server ~]# cd /etc/pki/tls/private/
[root@server private]# openssl genrsa -aes128 2048 > jiami.key
[root@localhost certs]# cd /etc/pki/tls/certs/
[root@localhost certs]# openssl req -utf8 -new -key /etc/pki/tls/private/jiami.key -x509 -days 365 -out jiami.crt