web服务练习
要求:
-
综合练习:请给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访问
实现
下载软件
bash
[root@server ~]# yum install httpd -y
[root@server ~]# yum install httpd mod_ssl -y
新建网页文件
bash
[root@server ~]# mkdir -p /www/openlab
[root@server ~]# mkdir -p /www/openlab/data
[root@server ~]# mkdir -p /www/openlab/student
[root@server ~]# mkdir -p /www/openlab/money
向网页文件中插入内容
bash
[root@server ~]# echo "welcome to openlab.com" > /www/openlab/index.html
[root@server ~]# echo "welcome to data" > /www/openlab/data/index.html
[root@server ~]# echo "welcome to student" > /www/openlab/student/index.html
[root@server ~]# echo "welcome to money" > /www/openlab/money/index.html
新建运行登录账户
bash
[root@server ~]# useradd song
[root@server ~]# passwd song
[root@server ~]# useradd tian
[root@server ~]# passwd tian
设置网页账户登录密码
bash
[root@server ~]# htpasswd -c /etc/httpd/passwd song
New password:
Re-type new password:
Adding password for user song
[root@server ~]# htpasswd -c /etc/httpd/passwd tian
New password:
Re-type new password:
Adding password for user tian
配置加密https访问
bash
# 设置私钥文件
[root@server ~]# openssl genrsa -aes128 2048 > /etc/pki/tls/private/money.key
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
# 设置数字证书
[root@server cert]# openssl req -utf8 -new -key /etc/pki/tls/private/money.key -x509 -days 365 -out /etc/pki/tls/cert/money.crt
修改主配置文件
bash
# 主网站的虚拟主机搭建
<virtualhost 192.168.216.136>
documentroot /www/openlab
servername 'www.openlab.com'
<directory /www/openlab>
allowoverride none
require all granted
</directory>
</virtualhost>
# data网站的虚拟主机搭建
<virtualhost 192.168.216.136>
documentroot /www/openlab/data
alias /data /www/openlab/data
servername 'www.openlab.com'
<directory /www/openlab/data>
allowoverride none
require all granted
</directory>
</virtualhost>
# student网站的指定用户密码搭建
<directory /www/openlab/student>
authuserfile /etc/httpd/passwd
authname 'student'
authtype basic
require user song tian
</directory>
# money网站的https加密搭建
<virtualhost 192.168.216.136:443>
sslengine on
SSLCertificateFile /etc/pki/tls/cert/money.crt
SSLCertificateKeyFile /etc/pki/tls/private/money.key
documentroot /www/openlab
alias /money /www/openlab/money
servername 'www.openlab.com'
<directory /www/openlab/money>
allowoverride none
require all granted
</directory>
</virtualhost>
注意:在修改配置文件后一定要重启服务