一、修改apache目录下的 httpd.conf 配置文件
1、#LoadModule ssl_module modules/mod_ssl.so 删除行首的配置语句注释符号“#”
2、增加一条引用语句 Include conf/vhostsssl.conf
二、配置文件创建
1、在conf文件夹中创建一个vhostsssl.conf配置文件。
2、编辑 vhostsssl.conf 文件,增加如下内容:
Listen 443 <VirtualHost *:443> ServerName www.gworg.cn ServerAlias gworg.cn SSLEngine on SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLCertificateFile "D:/ssl/2_www.gworg.com.crt" SSLCertificateKeyFile "D:/ssl/3_www.gworg.com.key" SSLCertificateChainFile "D:/ssl/1_root_bundle.crt" DocumentRoot "D:/APP" <Directory /> Options -Indexes -FollowSymLinks +ExecCGI AllowOverride All Order allow,deny Allow from all Require all granted </Directory> </VirtualHost>
文件代码说明
SSLCertificateFile 证书公钥
SSLCertificateKeyFile 证书私钥
SSLCertificateChainFile CA根证书
DocumentRoot 网站WEB目录
三、phpstudy 配置强制https访问(自动跳转HTTPS),伪静态 .htaccess 文件中配置。通道:301跳转代码
<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] </IfModule>
四、保存退出,并重启Apache。
PS:Apache 启动不了,一般是配置文件不对,请耐心排查。一般启动不了是因为之前配置过SSL或者文件配置错误!
httpd.conf 文件一般目录,phpStudy安装软件目录:
C:\phpStudy\Apache\conf 或者 D:\phpStudy\PHPTutorial\Apache\conf
vhostsssl.conf 备用代码,针对phpStudy2012-2014叫老的版本:
Listen 443 <VirtualHost www.gworg.com:443> SSLEngine On SSLCertificateFile "D:/ssl/2_www.gworg.com.crt" SSLCertificateKeyFile "D:/ssl/3_www.gworg.com.key" SSLCertificateChainFile "D:/ssl/1_root_bundle.crt" #...... DocumentRoot "D:/APP" ServerName www.gworg.com:443 </VirtualHost>