综合练习:请给openlab搭建web网站网站需求:
1.基于域名www.openlab.com可以访问网站内容为 welcome to openlab!!!
# 恢复快照,关闭安全软件
# 安装所需软件
[root@server ~]# yum install httpd mod_ssl -y
# hosts映射
[root@server ~]# vim /etc/hosts
192.168.48.130 www.openlab.com
# 创建网页目录及网页
[root@server ~]# mkdir -p /www/openlab
[root@server ~]# echo 'welcom to openlab' > /www/openlab/index.html
[root@server ~]# vim /etc/httpd/conf/httpd.conf # 定位第一行
<VirtualHost 192.168.48.130>
DocumentRoot /www/openlab
ServerName "www.openlab.com"
<Directory /www/openlab>
AllowOverride None
require all granted
</Directory>
</VirtualHost>
[root@server ~]# systemctl restart httpd
# linux端打开浏览器输入www.openlab.com测试
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于
www.openlab.com/student 网站访问学生信息,www.openlab.com/data网站访问教学资料
www.openlab.com/money网站访问缴费网站。
3.要求
(1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。(2)访问缴费网站实现数据加密基于https访问。
第一步:创建教学资料子网站www.openlab.com/data
[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.48.130>
DocumentRoot /www/openlab/data
alias /data /www/openlab/data
ServerName "www.openlab.com"
<Directory /www/openlab/data>
AllowOverride none
require all granted
</Directory>
</VirtualHost>
[root@server ~]# systemctl restart httpd
# linux端打开浏览器输入www.openlab.com/data测试
第二步:创建学生信息子网站www.openlab.com/student
[root@server ~]# mkdir /www/openlab/student
[root@server ~]# echo 'student' > /www/openlab/student/index.html
[root@server ~]# useradd song
[root@server ~]# passwa song # 密码123456
[root@server ~]# useradd tian
[root@server ~]# passwd tian # 密码654321
[root@server ~]# htpasswd -c /etc/httpd/passwd song # 密码123456
[root@server ~]# htpasswd /etc/httpd/passwd tian # 密码654321
[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>
[root@server ~]# systemctl restart httpd
# linux端打开浏览器输入www.openlab.com/student测试,多次测试需要清除浏览器缓存
第三步:创建缴费子网站www.openlab.com/money
[root@server ~]# mkdir /www/openlab/money
[root@server ~]# echo 'money' > /www/openlab/money/index.html
[root@server ~]# openssl genrsa -aes128 2048 > /etc/pki/tls/private/money.key
Enter PEM pass phrase: # 私钥加密密码123456
Verifying - Enter PEM pass phrase: # 在输入一遍123456
[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: # 输入私钥加密密码123456
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]: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) []:www.openlab.com
Email Address []:andy@openlab.com
[root@server ~]# vim /etc/httpd/conf/httpd.conf
<VirtualHost 192.168.48.130:443>
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/money.crt
SSLCertificatekeyFile /etc/pki/tls/private/money.key
ServerName www.openlab.com
DocumentRoot /www/openlab
alias /money /www/openlab/money
<Directory /www/openlab/money>
AllowOverride none
require all granted
</Directory>
</VirtualHost>
[root@server ~]# systemctl restart httpd # 需要输入私钥加密密码123456
🔐 Enter TLS private key passphrase for www.openlab.com:443 (RSA) : ******
# linux端打开浏览器输入https://www.openlab.com/money测试