1.下载包含OpenSSL的Apache Http Server。
安装apache
可通过查看是否有一下文件,来确认:
[Apache安装目录]/modules/ mod_ssl.so
[Apache安装目录]/bin/ openssl.exe, libeay32.dll, ssleay32.dll
[Apache安装目录]/conf/ openssl.cnf
2.http.conf
去掉注释:
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf
httpd-ssl.conf 中内容如下:
Listen 443
SSLSessionCache "shmcb:c:/Apache24/logs/ssl_scache(512000)"
SSLSessionCacheTimeout 300
SSLCipherSuite HIGH:MEDIUM:!MD5:!RC4
SSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4
SSLHonorCipherOrder on
SSLCompression off
SSLProtocol All -SSLv2 -SSLv3
SSLProxyProtocol All -SSLv2 -SSLv3
3.生成指定域名证书
1).cmd
进入 apache安装目录bin下
2).生成 server.key
openssl genrsa 1024 >server.key
(RSA密钥对的默认长度是1024,取值是2的整数次方,并且密钥长度约长,安全性相对会高点)
如果在执行这条命令时提示找不到/conf/openssl.cnf的话,就在执行这条命令前加一条命令为:
set openssl_conf=../conf/openssl.cnf
等密钥server.key生产完毕后进行下一步操作。
3)生成server.csr
继续在bin目录下执行命令:
openssl req -new -config ../conf/openssl.cnf -key server.key >server.csr
#(如果不加-config ../conf/openssl.cnf参数的话,常会报Unable to load config info from /usr/local/ssl/openssl.cnf)
#然后就会要求输入一系列的参数:
Country Name (2 letter code) [AU]:CN ISO #国家代码(只支持两位字符)
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) []: #申请证书的域名
Email Address []:admin@admin.com #管理员邮箱
Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: #交换密钥
An optional company name []:
#注: Common Name 必须和 httpd.conf 中 server name 必须一致, 否则 apache 不能启动(启动 apache 时错误提示为: server RSA certificate CommonName (CN) `Kedou' does NOT match server name!? )
4)签署服务器证书文件 server.crt
继续在 bin 目录,执行命令行 命令:
openssl req -x509 -days 4000 -config ../conf/openssl.cnf -key server.key -in server.csr >server.crt
说明:这是用步骤 1,2 的的密钥和证书请求生成证书 server.crt,-days 参数 指明证书有效期,单位为天,x509 表示生成的为 X.509 证书。
5)将bin下的
server.crt
server.csr
server.key
复制到Apache的conf目录下。
4.项目配置
以test.local为例:
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "D:/phpapache/Apache24/conf/server.crt"
SSLCertificateKeyFile "D:/phpapache/Apache24/conf/server.key"
ServerName test.local
DocumentRoot "F:\www\test"
<Directory "F:\www\test">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
5.重启apache