要求:搭建一个基于https://www.zuoye.com访问的web网站,网站首页在/www/https/,内容为exercise。
https的服务,私钥及证书
[root@server1 ~]# yum -y install httpd
[root@server1 ~]# yum -y install mod_ssl
#生成私钥和证书:
[root@server1 ~]# cd /etc/pki/tls/certs/ #配置文件
[root@server1 certs]# openssl genrsa -aes128 2048 > czc.key #生成私钥
[root@server1 certs]# openssl req -utf8 -new -key czc.key -x509 -days 365 -out czc.crt #生成证书
Enter pass phrase for czc.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) []:sc
Locality Name (eg, city) [Default City]:cd
Organization Name (eg, company) [Default Company Ltd]:open
Organizational Unit Name (eg, section) []:ce
Common Name (eg, your name or your server's hostname) []:www.zuoye.com
Email Address []:admin@admin
[root@server1 certs]# ll
total 8
lrwxrwxrwx. 1 root root 49 Jun 17 2021 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
lrwxrwxrwx. 1 root root 55 Jun 17 2021 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-rw-r--r--. 1 root root 1261 Nov 23 23:41 czc.crt
-rw-r--r--. 1 root root 1766 Nov 23 23:39 czc.key
关闭防火墙及SELinux
[root@server1 certs]# systemctl stop firewalld.service
[root@server1 certs]# setenforce 0
创建目录并编写网页内容
[root@server1 ~]# mkdir -pv /www/https
[root@server1 ~]# echo "exercise" > /www/https/index.html
编写配置文件
[root@server1 ~]# cd /etc/httpd/conf.d/
[root@server1 conf.d]# vim zuoye.conf
<Directory /www/https>
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<VirtualHost 192.168.210.11:443>
DocumentRoot "/www/https"
ServerName www.zuoye.com
ErrorLog "/var/log/httpd/zuoye_error_log"
CustomLog "/var/log/httpd/zuoye_access_log" common
SSLEngine on
sslcertificatefile /etc/pki/tls/certs/czc.crt
sslcertificatekeyfile /etc/pki/tls/certs/czc.key
</VirtualHost>
[root@server1 conf.d]# systemctl restart httpd #重启httpd服务
虚拟机和Windows主机的配置
虚拟机:
[root@server1 ~]# vim /etc/hosts
192.168.210.11 www.zuoye.com
主机文件路径:C:\Windows\System32\drivers\etc\hosts
注意:前面不能有“#”
最终测试: