实验步骤:
1.开启apache的ssl模块
#取消以下两行的注释
LoadModule ssl_module modules/mod_ssl.so
Include etc/extra/httpd-ssl.conf
2.CA证书申请(实验环境)
#创建存放密钥和证书文件的目录
mkdir /usr/local/apache2/cert && cd /usr/local/apache2/cert
(1)生成服务器私钥,RSA密钥
openssl genrsa -out ca.key 1024
(2)生成csr证书文件,依次输入国家、地区、城市、组织、组织单位、名字或域名、email等
openssl req -new -key ca.key -out ccku.csr
(3)设置证书文件*.crt的有效期等信息
openssl x509 -req -days 365 -sha256 -in ccku.csr -signkey ca.key -out ccku.crt
3.修改配置文件
(1)修改 httpd-ssl.conf文件,调用证书
#vim /usr/local/apache2/etc/extra/httpd-ssl.conf
#注释掉不安全的协议
#添加:
SSLProtocol all -SSLv2 -SSLv3
#修改加密套件
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
SSLCertificateFile cert/ccku.crt
SSLCertificateKeyFile cert/ca.key
(2)修改apache的主配置文件,添加虚拟主机
<VirtualHost _default_:443>
DocumentRoot "/usr/local/apache2/htdocs"
ServerName localhost:443
SSLCertificateFile cert/ccku.crt
SSLCertificateKeyFile cert/ca.key
SSLCertificateChainFile cert/ccku.crt
</VirtualHost>
4.验证
(1)检查配置文件语法
apachectl -t
\#报错提示:
AH00526: Syntax error on line 83 of /usr/local/apache2/etc/extra/httpd-ssl.conf:
SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).
#解决办法:修改主配置文件调用该模块
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so #取消注释
重新检查语法验证
#apachectl -t
Syntax OK
(2)重启apache,使用https测试
apachectl restart
5.强制跳转https
#vim /usr/local/apache2/etc/httpd.conf
#在<Directory "/usr/local/apache2/htdocs">标签下添加:
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https//%{SERVER_PORT}/$1 [R=301,L]
6.关闭https的方法:
1.ssl配置文件调用
2.虚拟主机
3.跳转