Apache 配置HTTPS协议搭载SSL配置

 在设置Apache + SSL以前, 须要作:apache

    安装Apache, 请参见: Windows环境下Apache的安装与虚拟目录的配置, 下载安装Apache时请下载带有ssl版本的Apache安装程序.
 
    在进行下一步以前, 请确认Apache已经安装并能够正常工做. 而且ssl须要的文件在以下的位置:
    [Apache安装目录]/modules/ mod_ssl.so
    [Apache安装目录]/bin/ openssl.exe, libeay32.dll, ssleay32.dll
    [Apache安装目录]/conf/ openssl.cnf
建立SSL证书
打开CMD,进入到Apache安装目录下的bin目录下
执行命令:
openssl genrsa 1024 >server.key
(RSA密钥对的默认长度是1024,取值是2的整数次方,而且密钥长度约长,安全性相对会高点)
若是在执行这条命令时提示找不到/conf/openssl.cnf的话,就在执行这条命令前加一条命令为:
set openssl_conf=../conf/openssl.cnf
 
等密钥server.key生产完毕后进行下一步操做。
 
生产为签署的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!? )
签署服务器证书文件 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 证书。
在bin 目录下,找到
server.crt
server.csr
server.key
三个文件,将此三个文件复制到Apache的conf目录下。
 
配置 httpd.conf. 在Apache的conf\extra目录下的 httpd_ssl.conf 文件是关于 ssl 的配置,是 httpd.conf 的一 部分。
在 httpd.conf 中
找到下列行
LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf
去掉前面的#
将ServerName 后面的80改成443.
保存httpd.conf.
在conf\extra目录下,编辑 httpd_ssl.conf
 
找到
<VirtualHost _default_:443>
修改如下内容
SSLEngine On 
SSLCertificateFile "C:/Program Files/Apache Software Foundation/Apache2.2/conf/server.crt"(选择刚刚建立的证书目录)
SSLCertificateKeyFile "C:/Program Files/Apache Software Foundation/Apache2.2/conf/server.key"
保存后,重启Apache 服务。
经过WEB访问https://locakhost.看是否能正常访问,若是能够访问就说明配置成功。