题目:
搭建一个基于https://www.zuoye.com:4443访问的web网站,网站首页在/www/https/,内容为zuoye
一.在虚拟机中安装https服务
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# yum install mod_ssl -y
二.创建对应目录,定义网页内容
[root@localhost ~]# mkdir /www/https -v
mkdir: created directory '/www/https'
[root@localhost ~]# echo zuoye > /www/https/index.html
[root@localhost ~]# cat /www/https/index.html
zuoye
三.定义配置文件/etc/httpd/conf.d/https.conf
[root@localhost ~]# vim /etc/httpd/conf.d/https.conf
listen 4443
<VirtualHost 192.168.136.140:4443>
DocumentRoot /www/https
ServerName www.zuoye.com
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/https.crt
SSLCertificateKeyFile /etc/pki/tls/certs/https.key
</VirtualHost>
<Directory /www/https>
AllowOverride None
Require all granted
</Directory>
四.生成密钥和证书
[root@localhost conf.d]# cd /etc/pki/tls/certs/
[root@localhost certs]# openssl genrsa -aes128 2048 > https.key
[root@localhost certs]# ls
ca-bundle.crt ca-bundle.trust.crt https.key
[root@localhost certs]# openssl req -utf8 -new -key https.key -x509 -days 365 -out https.crt -set_serial 0
Enter pass phrase for https.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@localhost certs]# ls
ca-bundle.crt ca-bundle.trust.crt https.crt https.key
五.在虚拟机和Windows主机上添加域名
[root@localhost ~]# vim /etc/hosts
192.168.136.140 www.zuoye.com
C:\Windows\System32\drivers\etc\hosts
192.168.136.140 www.zuoye.com
六.关闭selinux和防火墙,重启httpd服务
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl restart httpd
Enter TLS private key passphrase for www.zuoye.com:443 (RSA) : ****
七.测试
[root@localhost ~]# curl https://192.168.136.140:4443 -k
zuoye
[root@localhost ~]# curl https://www.zuoye.com:4443 -k
zuoye