wamp配置ssl

发布时间:2018/7/11 9:07:33 打印 字号:

最应该知道wamp下apache是怎么报错的

c:\wamp\bin\apache\apache2.4.9\bin\httpd.exe -t

修改文件前请先复制备份。

查看端口netstat -aon|findstr "443"

1.开启ssl

C:/wamp/bin/apache/apache2.4.9/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

这三个文件前面的#去掉。

开启2个模块和ssl配置项的引入。

2.修改ssl配置项

C:/wamp/bin/apache/apache2.4.9/conf/extra/httpd-ssl.conf

先做一个全局替换,因为这里的路径是c:/Apache24,把他换成你的wamp路径。

下面是我文件的全部配置,我把注释的行全都删掉了,剩下这些,因为改了什么我不记得了。

Listen 443
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLPassPhraseDialog  builtin
SSLSessionCache        "shmcb:C:/wamp/bin/apache/apache2.4.9/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300
<VirtualHost _default_:443>
DocumentRoot "C:/wamp/www/"
ServerName _default_:443
ServerAdmin admin@example.com
ErrorLog "c:/wamp/logs/sslerror_log"
TransferLog "c:/wamp/logs/sslaccess_log"
SSLEngine on
SSLCertificateFile "C:/wamp/bin/apache/apache2.4.9/key/server.crt"
SSLCertificateKeyFile "C:/wamp/bin/apache/apache2.4.9/key/server.key"
# 如果是切换双向认证,下面3行注释去掉
#SSLCACertificateFile "c:/wamp/bin/apache/apache2.4.9/key/root.crt"
#SSLVerifyClient require
#SSLVerifyDepth  1
<FilesMatch "\.(cgi|shtml|phtml|php)$">
    SSLOptions +StdEnvVars
</FilesMatch>
<Directory "C:/wamp/bin/apache/apache2.4.9/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-5]" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0
CustomLog "C:/wamp/bin/apache/apache2.4.9/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>

3.生成文件生成步骤

准备

在Apache2.4.9目录下新建一个key文件夹;一下内容是按照openssl.cnf里配置的,注意大小写,你可以根据需求更改。

在key文件夹里新建一个demoCA的文件夹;
在demoCA文件夹里新建newcerts文件夹;
在demoCA文件夹里新建index.txt空文件;

在demoCA文件夹里新建serial文件(没有扩展名),第一行写01回车。

生成

1.引入配置文件

set OPENSSL_CONF=../conf/openssl.cnf //这个路径注意下应该没错

2.生成秘钥

openssl genrsa > root.key   // 生成根密钥openssl genrsa > server.key  // 生成服务端密钥openssl genrsa > client.key  // 生成客户端密钥

我故意用了不同的写法,前一篇的写法和这里一样的

openssl genrsa -out myCA.key 1024

为什么是1024,因为刚刚引入的配置文件,可以不加。

3.生成证书和csr文件

openssl req -x509 -new -key root.key >root.crt //根证书就是CA,之前说过,注意CA的CN和后面2个的不同。openssl req -new -key server.key -out server.csropenssl req -new -key client.key -out client.csr

我把他们写在一起,希望大家对比CA和csr文件的区别。

4.签名

openssl ca -in server.csr -cert root.crt -keyfile root.key -out server.crtopenssl ca -in client.csr -cert root.crt -keyfile root.key -out client.crt

生成第一个crt以后,demoCA中会多很多文件,找到index.txt.attr,更改这里,unique_subject = no;你就可以生成CN相同的crt了

5.生成pfx文件

openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.pfx

这个是要装在客户端的。

我只配通了ie firefox 和 chrome的单向认证,以及chrome的双向认证(去掉注释)。