配置Apache服务器支持https协议和SSL证书,最基本的要求是Apache包含openssl模块。还好apache/bin目录下有libeay32.dll
、openssl.exe
、ssleay32.dll
,自带了ssl模块,若没有该模块,需自行下载单独的openssl。php
启动模块比较简单,打开apache的配置文件conf/httpd.conf,去掉ssl模块前面的#css
LoadModule ssl_module modules/mod_ssl.so ... Include conf/extra/httpd-ssl.conf
若是你有证书了,那么会有malinlin.cn.crt
malinlin.cn.key
,两个文件,在conf下创建个ssl文件夹存放证书。将原先conf/extra/httpd-ssl.conf
备份后,新建一个httpd-ssl.conf
。如下是我为蛋总配置的:git
Listen 443 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLPassPhraseDialog builtin <VirtualHost *:443> DocumentRoot "c:/wamp/www" ServerName malinlin.cn:443 ServerAdmin admin@example.com ErrorLog "C:/wamp/bin/apache/apache2.2.22/logs/ssl-error.log" TransferLog "C:/wamp/bin/apache/apache2.2.22/logs/sll-access.log" SSLEngine on SSLCertificateFile "C:/wamp/bin/apache/apache2.2.22/conf/ssl/malinlin.cn.crt" SSLCertificateKeyFile "C:/wamp/bin/apache/apache2.2.22/conf/ssl/malinlin.cn.key" SSLCertificateChainFile "C:/wamp/bin/apache/apache2.2.22/conf/ssl/malinlin.cn.crt" </VirtualHost>
若是想在原先httpd-sll.conf修改也行,记得将这三行注释掉。没有注释的话启动wamp会是失败的枯黄色。算法
#SSLSessionCache "dbm:D:/wamp/bin/apache/apache2.4.9/logs/ssl_scache" #SSLSessionCache "shmcb:D:/wamp/bin/apache/apache2.4.9/logs/ssl_scache(512000)" #SSLSessionCacheTimeout 300
配置好后重启wamp,重启完毕后,浏览器就能够访问了。apache
若是到这已经解决你的问题了,那就不必往下看了,下面是介绍没有证书的状况下也能体验,咱们强大的openssl也是能够生成证书的,以后访问https://localhost
(哎,什么域名都是ok的啦)vim
由于该目录才有libeay32.dll
、openssl.exe
、ssleay32.dll
等文件。浏览器
使用DOS命令在bin目录下执行命令:set OPENSSL_CONF=..\conf\openssl.cnf,经过此命令设置openssl的环境变量,若是不执行此命令,后面的操做会报错。服务器
set OPENSSL_CONF=..\conf\openssl.cnf
DOS下执行命令:openssl genrsa 4096 > server.key,执行了这个命令,会在bin目录下生成server.key。注释:这是使用128位的RSA算法生成的密钥,还可使用其余的算法生成密钥,相关的用法可使用搜索引擎搜索。4096是密钥的长度,这个值最好使用4096以上的值,必须是2的整数次方。测试
openssl genrsa 4096 > server.key
DOS命令下执行:openssl req -new -key server.key > server.csr,这个命令使用生成的密钥文件 server.key生成证书请求文件server.csr,执行这一命令以后,后面还要输入不少参数。ui
openssl req -new -key server.key > server.csr Country Name (2 letter code) [AU]:CN ISO国家代码(只支持两位字符) State or Province Name (full name) [Some-State]:Hu Bei 所在省份 Locality Name (eg, city) []:Wu Han 所在城市 Organization Name (eg, company) [Internet Widgits Pty Ltd]:Mark Company 公司名称 Organizational Unit Name (eg, section) []:IT 组织名称 Common Name (e.g. server FQDN or YOUR name) []:www.phpmarker.com 申请证书的域名 Email Address []:phpmarker@163.com 管理员邮箱 Please enter the following ‘extra’ attributes to be sent with your certificate request A challenge password []: 交换密钥 可空 An optional company name []: 可空
DOS命令下执行:openssl req -x509 -days 365 -key server.key -in server.csr > server.crt,这个命令使用第三步和第四步生成的密钥和证书来生成证书server.crt,-days参数表示证书有效期,单位为天,x509表示生成的是X.509证书。
openssl req -x509 -days 365 -key server.key -in server.csr > server.crt
DOS下执行命令:openssl x509 -noout -text -in server.crt,这个命令能够查看证书的详细信息
openssl x509 -noout -text -in server.crt
执行上面全部的命令以后,在Apache的bin目录下生成了三个文件server.key
、server.csr
、server.crt
。能够将其移动到专门放证书的文件夹。
修改httpd-ssl.conf,如下是个人配置:
Listen 443 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLPassPhraseDialog builtin #SSLSessionCache "dbm:D:/wamp/bin/apache/apache2.4.9/logs/ssl_scache" #SSLSessionCache "shmcb:D:/wamp/bin/apache/apache2.4.9/logs/ssl_scache(512000)" #SSLSessionCacheTimeout 300 <VirtualHost _default_:443> DocumentRoot "e:/kuaipan/code/win_www" ServerName localhost:443 ServerAdmin admin@example.com ErrorLog "D:/wamp/bin/apache/apache2.4.9/logs/ssl-error.log" TransferLog "D:/wamp/bin/apache/apache2.4.9/logs/sll-access.log" SSLEngine on SSLCertificateFile "D:/wamp/bin/apache/apache2.4.9/conf/ssl/server.crt" SSLCertificateKeyFile "D:/wamp/bin/apache/apache2.4.9/conf/ssl/server.key" SSLCertificateChainFile "D:/wamp/bin/apache/apache2.4.9/conf/ssl/server.crt" </VirtualHost>
重启后浏览器访问https://localhost
可用,可是https是个叉,不像上面的图是绿色的。出现这种状况,由于咱们本身制做的证书,不被浏览器所信赖。咱们查看证书详细状况: