域名已经备案的前提下
1、在腾讯月云上申请ssl证书(对于个人可以用免费版)
2、下载证书,增加一条域名解析,采用txt解析方式
3、将证书上传到服务器端,比如apache的conf文件夹下,新建一个cert文件夹,将下载的证书中三个都保存到cert文件夹下
4、开启ssl扩展,并在conf下的httpd.conf文件中将#LoadModule ssl_module modules/mod_ssl.so和#Include conf/extra/httpd-ssl.conf这两项的#去掉
如果此时:#Include conf/extra/httpd-ssl.conf中的#去掉之后apache报错无法启动,此时的错误是conf/extra/httpd-ssl.conf文件有错误可以将此文件所有内容删除
5、在conf/extra/httpd-ssl.conf文件中中下面内容替换
Listen 443
<VirtualHost *:443>
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile "D:/phpStudy/Apache/conf/cert/2_www.yourmain.com.crt"
SSLCertificateKeyFile "D:/phpStudy/Apache/conf/cert/3_www.yourmain.com.key"
SSLCertificateChainFile "D:/phpStudy/Apache/conf/cert/1_root_bundle.crt"
DocumentRoot "D:\phpStudy\WWW\test"
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
6、重启服务器,https成功配置
最后:从http跳转到https
修改apache
7、修改conf/httpd.conf中:
LoadModule rewrite_module modules/mod_rewrite.so 前面#去掉
AllowOverride None 修改为 AllowOverride All
8、在项目入口目录下添加.htaccess
并加入
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
</IfModule>