综合练习: 请给openlab搭建web网站
网站需求:
1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!
创建目录,在客户端中写入映射关系;将welcome to openlab ! 写入目录中;最后重启服务;
[root@localhost ~]#mkdir -pv /www/openlab
mkdir:已创建目录 '/www'
mkdir:已创建目录 '/www/openlab'
[root@localhost ~]#vim /etc/hosts
127.0.0.1 localhost losalhost.localdomain localhost4 localhost4.localdomain
::1 localhost losalhost.localdomain localhost6 localhost6.localdomain
192.168.67.128 www.openlab.com
[root@localhost ~]#echo welcome to openlab ! >/www/openlab/index.html
[root@localhost ~]#systemctl restart httpd
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于[www.openlab.com/student ]网站访问学生信息,[www.openlab.com/data]网站访问教学资料,[www.openlab.com/money] 网站访问缴费网站
[root@localhost ~]# mkdir /www/openlab/student
[root@localhost ~]# mkdir /www/openlab/data
[root@localhost ~]# mkdir /www/openlab/money
[root@localhost ~]# echo student > /www/openlab/student/index.html
[root@localhost ~]# echo data > /www/openlab/data/index,html
[root@localhost ~]# echo money > /www/openlab/money/index.html
[root@localhost ~]# cat /www/openlab/student/index.html
创建两个用户tian和song
[root@localhost ~]# htpasswd -c /etc/httpd/user song
New password:
Re-type new password:
Adding password for user song
[root@localhost ~]# htpasswd /etc/httpd/user tian
New password:
Re-type new password:
Adding password for user tian
修改用户配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/userdir.conf
检测:
3.要求
(1) 学生信息网站只有song和tian两人可以访问,其他用户不能访问。
(2) 访问缴费网站实现数据加密基于https访问。
先安装mod_ssl插件
[root@localhost ~]# yum install mod_ssl
然后在/etc/pki/tls/private 目录下生成私钥文件
[root@localhost ~]# cd /etc/pki/tls/private/
[root@localhost private]# ll
总用量 0
[root@localhost private]# openssl genrsa -aes128 2048 > money.key
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
在/etc/pki/tls/certs目录下新建证书
[root@localhost private]# cd /etc/pki/tls/certs/
[root@localhost certs]# openssl req -utf8 -new -key /etc/pki/tls/private/money.key -x509 -days 365 -out 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]: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) []:localhost
Email Address []:money@qq.com
输入证书信息时,必须一次性写对,不能退格删除
主配置文件的编辑
/etc/httpd/conf.d/ssl.conf在结尾添加以下内容
<VirtualHost 192.168.38.128:443>
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/money.crt
SSLCertificateKeyFile /etc/pki/tls/private/money.key
ServerName www.openlab.com
DocumentRoot /www/openlab/money
</VirtualHost>
<Directory /www/openlab/money>
AllowOverride none
Require all granted
</Directory>
最后重启http服务
[root@localhost conf.d]# systemctl restart httpd
点击高级: