网站需求:
1.基于域名 www.openlab.com 可以访问网站内容为 welcome to openlab!!!
下载 httpd 服务,命令:dnf install httpd
进入 /etc/httpd/conf.d 下
conf.d 配置:
写本地解析 /etc/hosts
[root@localhost conf.d]# mkdir /www/lxm -p
[root@localhost conf.d]# echo "welcome to openlab "\!\!\!"" > /www/lxm/index.html
然后重启服务:
代码整理:
[root@localhost ~]# dnf install httpd
[root@localhost conf.d]# vim host.conf
[root@localhost conf.d]# vim /etc/hosts[root@localhost conf.d]# mkdir /www/lxm -p
[root@localhost conf.d]# echo "welcome to openlab "\!\!\!"" > /www/lxm/index.html
[root@localhost conf.d]# systemctl restart httpd
[root@localhost conf.d]# setenforce 0
[root@localhost conf.d]# curl www.openlab.com
2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,
1、基于 www.openlab.com/student 网站访问学生信息,
2、基于 www.openlab.com/data 网站访问教学资料
3、基于 www.openlab.com/money 网站访问缴费网站。
host.conf 配置:
<directory /www>
allowoverride none
require all granted
</directory>
<virtualhost 192.168.180.128:80>
ServerName www.openlab.com
documentroot /www/lxm
</virtualhost>
<virtualhost 192.168.180.128:80>
ServerName www.openlab.com
documentroot /www/lxm
Alias /student /www/lxm/student
</virtualhost>
<virtualhost 192.168.180.128:80>
Servername www.openlab.com
documentroot /www/lxm
Alias /data /www/lxm/data
</virtualhost>
<virtualhost 192.168.180.128:80>
Servername www.openlab.com
documentroot /www/lxm
Alias /money /www/lxm/money
</virtualhost>
hosts 添加如下:
代码整理:
[root@localhost conf.d]# vim host.conf
[root@localhost conf.d]# mkdir /www/lxm/student
[root@localhost conf.d]# mkdir /www/lxm/data
[root@localhost conf.d]# mkdir /www/lxm/money
[root@localhost conf.d]# echo "This is student " > /lxm/zuoye/student/index.html
[root@localhost conf.d]# echo "This is data " > /www/lxm/data/index.html
[root@localhost conf.d]# echo "This is money " > /www/lxm/money/index.html
[root@localhost conf.d]# vim /etc/hosts
[root@localhost conf.d]# systemctl restart httpd
3.要求
(1)学生信息网站只有 song 和 tian 两个用户可以访问,其他用户不能访问。
(2)访问缴费网站实现数据加密基于 https 访问。
首先需安装 mod_ssl 命令为: dnf install mod_ssl
ssl.conf 添加如下:
Conmon Name根据地址来写。
然后在防火墙上永久性地添加规则,允许TCP协议的443端口通过防火墙。
重启后就可使用curl访问:
代码整理:
[root@localhost conf.d]# dnf install mod_ssl
[root@localhost conf.d]# vim /etc/httpd/conf.d/ssl.conf
[root@localhost conf.d]# yum install mod_ssl httpd - y
[root@localhost conf.d]# cd /etc/pki/tls/certs/
[root@localhost certs]# openssl genrsa - aes128 2048 > jiami.key
[root@localhost certs]# openssl req -utf8 -new -key jiami.key -x509 -days 100 -out jiami.crt
[root@localhost certs]# vim /etc/httpd/conf.d/host.conf
[root@localhost certs]# firewall-cmd --permanent --add-port=443/tcp
[root@localhost certs]# systemctl restart httpd
/etc/httpd/conf.d/host.conf :
<directory /www>
allowoverride none
require all granted
</directory><directory /www/lxm/student>
authtype basic
authname "This is a private directory,Please Login: "
authuserfile /etc/httpd/lx
require user song tian
</directory>
<virtualhost 192.168.180.128:80>
ServerName www.openlab.com
documentroot /www/lxm
</virtualhost>
<virtualhost 192.168.180.128:80>
ServerName www.openlab.com
documentroot /www/lxm
Alias /student /www/lxm/student
</virtualhost>
<virtualhost 192.168.180.128:80>
Servername www.openlab.com
documentroot /www/lxm
Alias /data /www/lxm/data
</virtualhost>
<virtualhost 192.168.180.128:443>
Servername www.openlab.com
documentroot /www/lxm
Alias /money /www/lxm/money
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
</virtualhost>