为Wampserver中的apache配置https协议

一、设置环境变量

1、管理员权限运行CMD(快捷键win+r,输入cmd),cd D:\wamp\bin\apache\Apache2.4.23\conf
2、set OPENSSL_CONF=..\conf\openssl.cnf

二、生成server.key

1、cd D:\wamp\bin\apache\Apache2.4.23\bin
2、openssl genrsa 1024>server.key

三、生成server.csr

接着上边继续:
1、openssl req -new -key server.key > server.csr
2、按提示输入一系列的参数:
Country Name (2 letter code) [AU]:(ISO国家代码,只支持两位字符 例如:CN)

State or Province Name (full name) [Some-State]:(省份 例如:ZJ)

Locality Name (eg, city) []:(城市 例如:HZ)

Organization Name (eg, company):(输入公司名称)

Organizational Unit Name (eg, section) []:(输入组织名称)

Common Name (eg, YOUR name) []:( 申请证书的域名或者IP,本地可设置为localhost:8080 )

Email Address []:(输入管理员邮箱)

Please enter the following ‘extra’ attributes to be sent with your certificate request A challenge password []: (交换**)

注意:其中的Common Name只能输入域名或IP:
Common Name 必须和 httpd.conf 中 server name 必须一致(localhost:8080的时候可以不一致), 否则 apache 不能启动(启动 apache 时错误提示为: server RSA certificate CommonName (CN) `Kedou’ does NOT match server name!? )
最后的密码和公司名称可以为空

四、生成server.crt

接着上边继续:
1、openssl req -x509 -days 365 -key server.key -in server.csr > server.crt
2、在D:\wamp\bin\apache\Apache2.4.23\bin把 server.crt、server.csr、server.key
三个文件复制到D:\wamp\bin\apache\Apache2.4.23\conf 下

五、配置httpd:

打开’D:\wamp\bin\apache\Apache2.4.23\conf\httpd.conf’ 取消注释
Include conf/extra/httpd-ssl.conf
LoadModule ssl_module modules/mod_ssl.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so

六、配置ssl:

打开D:\wamp\bin\apache\Apache2.4.23\conf\extra\httpd-ssl.conf进行以下修改
1、”SSLCertificateKeyFile…”这行改成
SSLCertificateKeyFile “D:/wamp/bin/apache/apache2.4.23/conf/server.key”
2、SSLSessionCache这行改成
SSLSessionCache “shmcb:D:/wamp/bin/apache/apache2.4.23/logs/ssl_scache(512000)”
3、修改DocumentRoot 为DocumentRoot “D:/wamp/www/”
ServerName www.example.com:443
ErrorLog “D:/wamp/bin/apache/apache2.4.23/logs/error.log”
TransferLog “D:/wamp/bin/apache/apache2.4.23/logs/access.log”
4、SSLEngine on
SSLCertificateFile “D:/wamp/bin/apache/apache2.4.23/conf/server.crt”
SSLCertificateKeyFile “D:/wamp/bin/apache/apache2.4.23/conf/server.key
CustomLog “D:/wamp/bin/apache/apache2.4.23/logs/ssl_request.log”

七、重启wampserver。浏览器输入:https://localhost/

为Wampserver中的apache配置https协议
访问截图

八、常见错误以及解决建议:

1、openssl genrsa 1024>server.key时可能会出现“无法定位序数XX于动态链接库”的错误提示,可以通过百度搜索下载最新的libeay32.dll、ssleay32.dll替换D:\wamp\bin\apache\Apache2.4.23\bin下的文件并且复制一份放到C:\Windows\System32目录下;
2、配置完成发现无法开启apache可以运行CMD 进入 cd D:\wamp\bin\apache\Apache2.4.23\bin 目录下 输入 httpd 可以看到配置文件出现的错误,然后可以进行相应的修改。


参考文献:

1、http://blog.csdn.net/happyqyt/article/details/9335397
2、https://baijiahao.baidu.com/s?id=1561668071484860&wfr=spider&for=pc