综合练习:请给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访问。
1.挂载
[root@yy ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
mount: /dev/sr0 已经挂载或 /mnt 忙
/dev/sr0 已经挂载到 /run/media/liumou/RHEL-7.2 Server.x86_64 上
/dev/sr0 已经挂载到 /mnt 上
2安装httpd ssl 关闭防火墙及selinux
[root@yy ~]# systemctl stop firewalld
[root@yy ~]# setenforce 0
[root@yy ~]# yum install httpd
3.配置文件
<Directory /openlab>
ALLowOverride none
Require all granted
</Directory>
<Directory /openlab/student>
Authtype Basic
AuthName "this is private"
AuthUserfile /usr/local/htuser
Require user song tian
</Directory>
<VirtualHost 192.168.254.130:443>
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA
SSLCertificateFile /etc/pki/tls/certs/haha.crt
SSLCertificateKeyFile /etc/pki/tls/certs/haha.key
DocumentRoot /openlab
Alias /money/openlab/money
ServerName www.openlab.com
Errorlog "/var/log/httpd/dummy-host2.example.com-error_log"
Customlog "/var/log/httpd/dummy-host2.example.com-access_log " common
</VirtualHost>
<VirtualHost 192.168.254.130:80>
DocumentRoot /openlab
Servername www.openlab.com
Errorlog "/var/log/httpd/dummy-host2.example.com-error_log"
Customlog "/var/log/httpd/dummy-host2.example.com-access_log " common
</VirtualHost>
添加域名
[root@yy ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.254.130 www.openlab.com
目录
[root@yy ~]# mkdir /openlab/{student,data,money} -pv
mkdir: 已创建目录 "/openlab/student"
mkdir: 已创建目录 "/openlab/data"
mkdir: 已创建目录 "/openlab/money"
网站内容
[root@yy ~]# echo 'welcome to openlab!!!' > /openlab/index.html
[root@yy ~]# echo 'xueshengxinxi' > /openlab/student/index.html
[root@yy ~]# echo 'jiaoxueziliao' > /openlab/data/index.html
[root@yy ~]# echo 'jiaofeiwangzhan' > /openlab/money/index.html
添加用户
[root@yy ~]# htpasswd -c /usr/local/userfile tian
New password:
Re-type new password:
Adding password for user tian
[root@yy ~]# htpasswd -c /usr/local/userfile song
New password:
Re-type new password:
Adding password for user song
[root@yy ~]#
证书
[root@yy certs]# make haha.crt
umask 77 ; \
/usr/bin/openssl req -utf8 -new -key haha.key -x509 -days 365 -out haha.crt -set_serial 0
Enter pass phrase for haha.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.cn
Organizational Unit Name (eg, section) []:tech
Common Name (eg, your name or your server's hostname) []:www.openlab.com
Email Address []:openlab@openlab.cn
[root@yy certs]# systemctl restart httpd
Enter SSL pass phrase for www.openlab.com:443 (RSA) : ******
测试
[root@yy ~]# curl http://192.168.254.130
welcome to openlab!