给公司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访问。
方案实施
搭建整体环境
[root@server ~]# setenforce 0
[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# yum install httpd mod_ssl -y
[root@server ~]# systemctl start httpd
[root@server ~]# systemctl enable httpd
一、搭建openlab公司web网站主界面
(1)新建存储主网页文件的目录,写入网页数据生成主网页文件,并将其存放在对应目录下;
[root@server ~]# mkdir -p /www/openlab
[root@server ~]# echo "welcome to openlab!" > /www/openlab/index.html
(2)使用vim文本编辑器编辑httpd主配置文件/etc/httpd/conf/httpd.conf,在空白行增加对应虚拟主机内容和网页目录的权限;
[root@server ~]# vim /etc/httpd/conf/httpd.conf
<Virtualhost 192.168.73.134>
documentroot /www/openlab
servername "www.openlab.com"
</Virtualhost>
<Directory /www/openlab>
allowoverride none
require all granted
</Directory>
(3)在/etc/hosts文件中手动配置服务器IP地址与域名www.openlab.com的映射关系;
[root@server ~]# vim /etc/hosts
192.168.73.134 www.openlab.com
二、搭建openlab公司web网站子界面
1.搭建www.openlab.com/student网站访问学生信息,只允许song和tian两人访问,其他用户不能访问;
(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 ~]# mkdir /www/openlab/student
[root@server ~]# echo "学生信息" > /www/openlab/student/index.html
(3) 给song和tian两个账户设置访问网站的密码
[root@server ~]# htpasswd -c /etc/httpd/password song
New password:
Re-type new password: #密码123456
Adding password for user song
[root@server ~]# htpasswd /etc/httpd/password tian
New password:
Re-type new password: #密码654321
Adding password for user tian
(3)编辑httpd主配置文件,在空白行增加对应虚拟主机内容和网页目录的权限;
<Virtualhost 192.168.73.134>
alias /student /www/openlab/student
documentroot /www/openlab/student
servername "www.openlab.com/student"
</Virtualhost>
<Directory /www/openlab/student>
authuserfile /etc/httpd/password
authname "学生信息网站"
authtype basic
require user song tian
</Directory>
2.搭建www.openlab.com/data网站访问教学资料;
(1)新建存储网页文件的目录,写入网页数据生成网页文件,并将其存放在对应目录下;
[root@server ~]# mkdir /www/openlab/data
[root@server ~]# echo "教学资料" > /www/openlab/data/index.html
(2)编辑httpd主配置文件,在空白行增加对应虚拟主机内容和网页目录的权限;
<Virtualhost 192.168.73.134>
alias /data /www/openlab/data
documentroot /wwww/openlab/data
servername "www.openlab.com/data"
</Virtualhost>
<Directory /www/openlab/data>
allowoverride none
require all granted
</Directory>
3.搭建基于https访问并基于ssl 加密认证的www.openlab.com/money网站访问缴费信息。
(1)新建存储网页文件的目录,写入网页数据生成网页文件,并将其存放在对应目录下;
[root@server ~]# mkdir /www/openlab/money
[root@server ~]# echo "缴费信息!" > /www/openlab/money/index.html
(2)在/etc/pki/tls/private目录中生成私钥文件
[root@server ~]# openssl genrsa -aes128 2048 > /etc/pki/tls/private/money.key
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
[root@server ~]#
(3)在/etc/pki/tls/certs目录中生成证书
[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) []:shaanxi
Locality Name (eg, city) [Default City]:xi'an
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 []:123@qq.com
[root@server ~]#
(4)编辑ssl 主配置文件,在空白行增加对应虚拟主机内容和网页目录的权限;
<Virtualhost 192.168.73.134:443>
sslengine on
sslcertificatefile /etc/pki/tls/certs/money.crt
sslcertificatekeyfile /etc/pki/tls/private/money.key
servername "www.openlab.com/money"
documentroot /www/openlab/money
alias /money /www/openlab/money
</Virtualhost>
<Directory /www/openlab/money>
allowoverride none
require all granted
</Directory>
三、重启服务并测试
1.www.openlab.com
输入域名直接访问
2.www.openlab.com/student
(1)输入域名有验证密码的对话框弹出,输入账户+密码
(2)登录验证访问
3.www.openlab.com/data
输入域名直接访问
4.www.openlab.com/money
输入域名直接访问
输入https://www.openlab.com/money访问
测试完毕,收工!