网站需求:
-
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>关闭安全软件
[root@server ~]# setenforce 0
[root@server ~]# systemctl stop firewalld
2>安装所需软件
[root@server ~]# yum install httpd mod_ssl -y
3>hosts映射添加
[root@server ~]# vim /etc/hosts
第二步:创建www.openlab.com网站
1>创建网页目录及网页
[root@server ~]# mkdir -p /www/openlab
[root@server ~]# echo 'welcome to openlab' > /www/openlab/index.html
[root@server ~]# vim /etc/httpd/conf/httpd.conf
写入:
<virtualhost 192.168.118.129>
documentroot /www/openlab
servername "www.openlab.com"
<directory /www/openlab>
allowoverride none
require all granted
</directory>
</virtualhost>
2>重启服务
[root@server ~]# systemctl restart httpd #重启服务
3> 测试
[root@server ~]# firefox # linux端打开浏览器输入www.openlab.com测试
第三步:创建教学资料子网站www.openlab.com/data
1>创建网页目录及网页
[root@server ~]# mkdir /www/openlab/data
[root@server ~]# echo 'data' > /www/openlab/data/index.html
[root@server ~]# vim /etc/httpd/conf/httpd.conf
写入:
<virtualhost 192.168.118.129>
documentroot /www/openlab/data
alias /data /www/openlab/data
servername "www.openlab.com"
<directory /www/openlab/data>
allowoverride none
require all granted
</directory>
</virtualhost>
2>重启服务
[root@server ~]# systemctl restart httpd #重启服务
3> 测试
[root@server ~]# firefox # linux端打开浏览器输入www.openlab.com/data测试
第四步:创建学生信息子网站www.openlab.com/student
1>添加song和tian学生信息并设置密码
[root@server ~]# useradd song
[root@server ~]# passwd song
更改用户 song 的密码 。
新的密码:
无效的密码: 密码少于 8 个字符
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
[root@server ~]# useradd tian
[root@server ~]# passwd tian
更改用户 tian 的密码 。
新的密码:
无效的密码: 密码少于 8 个字符
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
2>创建存储登录网站的密码
[root@server ~]# htpasswd -c /etc/httpd/passwd song
New password:
Re-type new password:
Adding password for user song
[root@server ~]# htpasswd /etc/httpd/passwd tian
New password:
Re-type new password:
Adding password for user tian
3>创建网页目录及网页
[root@server ~]# mkdir -p /www/openlab/student
[root@server ~]# echo 'student' > /www/openlab/student/index.html
[root@server ~]# vim /etc/httpd/conf/httpd.conf
写入:
<directory /www/openlab/student>
authuserfile /etc/httpd/passwd
authname "student"
authtype basic
require user song tian
</directory>
4>重启服务
[root@server ~]# systemctl restart httpd #重启服务
5>测试
[root@server ~]# firefox # linux端打开浏览器输入www.openlab.com/student测试
第五步:创建缴费子网站www.openlab.com/money
1>创建验证证书真实性的私钥文件
[root@server ~]# openssl genrsa -aes128 2048 > /etc/pki/tls/private/money.key
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
2>创建数字证书
[root@server ~]# openssl req -utf8 -new -key /etc/pki/tls/private/money.key -x509 -days 365 -out /etc/pki/tls/certs/money.crt
Enter pass phrase for /etc/pki/tls/private/money.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:86
State or Province Name (full name) []:shanxi
Locality Name (eg, city) [Default City]:xianyang
Organization Name (eg, company) [Default Company Ltd]:openlab
Organizational Unit Name (eg, section) []:RHCE
Common Name (eg, your name or your server's hostname) []:server
Email Address []:hh@qq.com
3>创建网页目录及网页
[root@server ~]# mkdir -p /www/openlab/money
[root@server ~]# echo 'money' > /www/openlab/money/index.html
[root@server ~]# vim /etc/httpd/conf/httpd.conf
写入:
<virtualhost 192.168.118.129:443>
sslengine on
sslcertificatefile /etc/pki/tls/certs/money.crt
sslcertificatekeyfile /etc/pki/tls/private/money.key
documentroot /www/openlab
alias /data /www/openlab/money
servername www.openlab.com
<directory /www/openlab/money>
allowoverride none
require all granted
</directory>
</virtualhost>
4>重启服务
[root@server ~]# systemctl restart httpd
🔐 Enter TLS private key passphrase for www.openlab.com:443 (RSA) : ******
5>测试
[root@server ~]# firefox # linux端打开浏览器输入https://www.openlab.com/money测试