天天看点

Windows搭建Apache+SSL Https服务器

所需的环境参考上一篇文章,简单地搭建了一个Apache+PHP的服务器,这个apache是自带SSL的,

http://blog.csdn.net/wlmnzf/article/details/50229407

因为看到网上的各种教程不全还有很多错误,自己绕了好多弯最后参考了官方文档,才最终解决,所以这里综合各方大神所写的文章,改正和完善细节后再发一次。这里不得不说一下,官方文档虽然是英文的平时还特别低调,显得相当高冷,可是它却是我们最靠谱,最坚强的后盾。

1.修改两个配置文件,一个为conf/httpd.conf,另一个为conf/extra/httpd-ssl.conf

在httpd.conf中

a. 删掉以下语句前的’#’

#LoadModule ssl_module modules/mod_ssl.so
#Include conf/extra/httpd-mpm.conf 
#Include conf/extra/httpd-ssl.conf 
           

b. httpd-ssl.conf中把相应选项改成如下,有’#’的删掉

SSLCertificateFile "c:/Apache24/conf/server.crt"
SSLCertificateKeyFile "c:/Apache24/conf/server.key"
SSLCACertificateFile "c:/Apache24/conf/ca.crt"
SSLVerifyClient require
SSLVerifyDepth  
           

2.生成各种证书

进入Apache24\bin目录,在对应文件夹下打开cmd

这里需要一个openssl的配置文件openssl.cnf,如果他不在 conf文件夹下,可以去网上下一个,建议把它放到bin目录下,这样子敲命令比较方便

a. 首先要生成服务器端的私钥(key文件):

set OPENSSL_CONF=openssl.cnf
  openssl genrsa -des3 -out server.key 
           

b. 生成server.csr ,Certificate Signing Request(CSR),生成的csr文件交给CA签名后形成服务端自己的证书.屏幕上将有提示,依照其指示一步一步输入要求的个人信息即可.

c. 对客户端也作同样的命令生成key及csr文件

openssl genrsa -des3 -out client.key 
openssl req -new -key client.key -out client.csr -config openssl.cnf
           

d. CSR文件必须有CA的签名才可形成证书.可将此文件发送到verisign等地方由它验证,要交一大笔钱,何不自己做CA呢.

openssl req -new -x509 -keyout ca.key -out ca.crt -config openssl.cnf
           

e. 在bin目录下新建一个demoCA文件夹,进入它

新建newcerts文件夹,不需要进入

新建index.txt

新建serial,打开后输入01保存即可

f. 用生成的CA的证书为刚才生成的server.csr,client.csr文件签名:

openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config openssl.cnf

openssl ca -in client.csr -out client.crt -cert ca.crt -keyfile ca.key -config openssl.cnf
           

这里如果第二条指令出现下面这样的错误,进入demoCA,然后打开index.txt.attr,把它修改成unique_subject = no就可以了

Windows搭建Apache+SSL Https服务器

g. 生成一个ca.pfx,打开IE浏览器-》工具-》Internet选项-》内容-》证书,按照提示导入,这里要输入刚才生成 .pfx 过程中输入的密码

openssl pkcs12 -export -in ca.crt -inkey ca.key -out ca.pfx

.

以上操作生成了

client使用的文件有:ca.crt,client.crt,client.key

server使用的文件有:ca.crt,server.crt,server.key

把 ca.crt,server.crt,server.key复制到conf根目录下去

打开Apache Service Monitor ,点击重启或者启动,走你…..

然而并没什么卵用,apache爆炸了,可是我们并不需要报警,接下来我们将一步步解决这些错误,本人行走江湖多年,能力不高,所以错误百出,别的没能耐,但是对于找错误,还是相当有一手的(此处捂着嘴笑),下面贴出logs/error.log的错误信息

AH00558: httpd.exe: Could not reliably determine the server's fully qualified domain name, using fe80::9c8a:3195:d193:8d3c. Set the 'ServerName' directive globally to suppress this message

[Thu Dec  :: ] [ssl:warn] [pid :tid ] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]

[Thu Dec  :: ] [mpm_winnt:notice] [pid :tid ] AH00354: Child: Starting  worker threads.

[Thu Dec  :: ] [mpm_winnt:notice] [pid :tid ] AH00424: Parent: Received restart signal -- Restarting the server.

AH00526: Syntax error on line  of C:/Apache24/conf/extra/httpd-ssl.conf:
SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).

[Thu Dec  :: ] [mpm_winnt:notice] [pid :tid ] AH00364: Child: All worker threads have exited.
           

各种百度以后得到解决方案

.Syntax error on line  of C:/Apache24/conf/extra/httpd-ssl.conf:
SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).

在httpd.conf中找到下面这句话
#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
取消注释(删掉前面的"#")

.SSLPassPhraseDialog builtin is not supported on Win32(key file C:/Apache24/conf/server.key)

   这个是说Windows不支持加密密钥,还记得生成server.key输入的密码吗?没错就是它的锅,我们现在取消掉它,cmd输入

openssl rsa -in server.key -out server.key

把生成的server.key复制到conf目录下覆盖
然后打开httpd-ssl.conf 找到SSLPassPhraseDialog  builtin 在前面加上#
           

然后再次点击apache上的启动试试,然后就SSL走起了。

浏览器输入https://127.0.0.1/index.php就可以观望到自己的https站点了。

参考资料

http://httpd.apache.org/docs//ssl/

http://blog.csdn.net/decajes/article/details/

http://blog.chinaunix.net/uid--id-html

http://impradeep.com/apacheconfextrahttpd-ssl-conf-error/

http://m.blog.csdn.net/blog/kuixinpei/
           

鸣谢

感谢楼上各位大神的幸苦探索

感谢 网易云音乐 歌单《夜的钢琴曲 Demo集》--石进 在我烦躁得仿佛万千草泥马奔腾而过以及想出门日狗的时候及时阻止了我。

感谢 网易云音乐 《当你》--林俊杰 的深夜相伴