过程:
1.安装httpd包和mod_ssl包
[root@localhost ~]# yum install httpd -y
[root@desktop ~]# yum install mod_ssl -y
[root@kaikai ~]# systemctl stop firewalld
[root@kaikai ~]# setenforce 0
2.编写配置文件
[root@desktop conf.d]# vim /etc/httpd/conf.d/vhosts-openlab.conf
1 <VirtualHost 192.168.248.128:80>
2 DocumentRoot /www/openlab
3 alias /student /student
4 alias /data /data
5 ServerName www.openlab.com
6 </VirtualHost>
7 <Directory /www>
8 AllowOverride none
9 Require all granted
10 </Directory>
11 <Directory /student>
12 Authtype Basic
13 AuthName "Student"
14 AuthUserFile /etc/httpd/users
15 Require user song tian
16 </Directory>
17 <Directory /data>
18 AllowOverride none
19 Require all grabted
20 </Directory>
21 <VirtualHost 192.168.248.128:443>
22 SSLEngine on
23 SSLCertificateFile /etc/pki/tls/certs/openlabl.crt
24 SSLCertificatekeyFile /etc/pki/tls/private/openlab1.key
25 DocumentRoot /www/openlab
26 alias /money网站访问缴费网站 /money
27 ServerName www.openlab.com
28 </VirtualHost>
29 <Directory /money>
30 AllowOverride none
31 Require all granted
32 </Directory>
3.生成私钥文件
[root@desktop private]# openssl genrsa -aes128 2048 > openlab.key
4.生成证书文件
[root@desktop certs]# openssl req -utf8 -new -key /etc/pki/tls/private/openlab.key -x509 -days 365 -out openlab.crt
5.创建目录并定义网页文件内容
[root@localhost data]# mkdir -p /www/openlab
[root@localhost data]# echo welcome to openlab! > /www/openlab/index.html
[root@localhost data]# vim /www/openlab/index.html
[root@localhost data]# mkdir /student
[root@localhost data]# echo this is student > /student/index.html
[root@localhost data]# mkdir /data
mkdir: 无法创建目录 “/data”: 文件已存在
[root@localhost data]# echo this is data > /data/index.html
[root@localhost data]# mkdir /money
[root@localhost data]# echo this is money > /money/index.html
[root@localhost data]# htpasswd -c /etc/httpd/users song
New password:
Re-type new password:
Adding password for user song
[root@localhost data]# htpasswd /etc/httpd/users tian
New password:
Re-type new password:
Adding password for user tian
[root@localhost data]# vim /etc/httpd/users
8.虚拟机缓存文件写入此域名解析条目(/etc/hosts)
[root@desktop ~]# vim /etc/hosts
9.本地主机缓存文件写入此域名解析条目(C:\Windows\System32\drivers\etc\hosts)
10.测试
root@localhost ~]# systemctl restart httpd
[root@localhost ~]# setenforce 0
#Client主机测试
[root@localhost ~]# curl www.openlab.com
welcome to openlab!