windows平台下配置apache+SSL

本文详细介绍了在Windows操作系统中如何配置Apache服务器以支持SSL。包括下载集成openssl的Apache版本,修改httpd.conf和httpd-ssl.conf文件,设置SSL证书,以及使用openssl命令生成私钥和证书请求文件。最后,文章提到了证书提交流程和测试证书的生成方法。
摘要由CSDN通过智能技术生成

 

一 、 可以下载与openssl已经集成好的apache版本,我下载的是: httpd-2.2.21-win32-x86-openssl-0.9.8r.msi

 

二 、 打开conf/httpd.conf文件

找到下面两行,并去掉前面的#号注释:

LoadModule ssl_module modules/mod_ssl.so

Include conf/extra/httpd-ssl.conf

 

三 、 修改httpd-ssl.conf文件

内容修改如下:

SSLCertificateFile "D:/Apache/Apache2.2.1-win32-x86-openssl/conf/server.crt"   改为自己的crt文件名

SSLCertificateKeyFile "D:/Apache/Apache2.2.1-win32-x86-openssl/conf/server.key"   改为自己的key文件名

将 

CustomLog "D:/Apache/Apache2.2.1-win32-x86-openssl/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
下面添加两行代码,修改为为:

CustomLog "D:/Apache/Apache2.2.1-win32-x86-openssl/logs/ssl_request.log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://cluster/

四 、 生成证书

我们可以直接使用apache目录bin下的openssl.exe,而不必再下载openssl进行安装。

使用命令行:

1. 生成私钥 .key

    Openssl > genrsa -des3 -out server.key 1024
    Loading 'screen' into random state - done
    Generating RSA private key, 1024 bit long modulus
    ............++++++
    ..........................++++++
    e is 65537 (0x10001)
    Enter pass phrase for server.key: mbi1001
    Verifying - Enter pass phrase for server.key:mbi1001

    由于使用 -des3 参数,需要输入一个密码对私钥进行加密,如不需要对私钥加密请不要使用-des3选项。
    结果生成 server.key 文件。


2.将私钥解密(可选):

    Openssl > rsa -in server.key -out server.decrypt-key
    Enter pass phrase for server.key:
    writing RSA key

    输入 pass phrase for server.key 后,生成解密后的 server.decrypt-key 文件。也可以使用未解密的文件。

3.根据.key生成证书请求文件.csr:

    Openssl > req -new -config ../conf/openssl.cnf -key server.key -out server.csr
    Enter pass phrase for server.key:mbi1001
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    What you are about to enter is what is called a Distinguished Name or a DN.
    There are quite a few fields but you can leave some blank
    For some fields there will be a default value,
    If you enter '.', the field will be left blank.
    -----
    Country Name (2 letter code) [AU]:CN
    State or Province Name (full name) [Some-State]:shaanxi
    Locality Name (eg, city) []:xian
    Organization Name (eg, company) [Internet Widgits Pty Ltd]:myCom Name
    Organizational Unit Name (eg, section) []:myOU Name
    Common Name (eg, YOUR name) []:localhost

    Email Address []:

    Please enter the following 'extra' attributes
    to be sent with your certificate request
    A challenge password []:mbi1001
    An optional company name []:

    Common Name 输入网站域名,否则会报告此证书不是为本网站颁发的。
    从Email地址开始,下面的信息可以不需要,保留为空,直接回车即可。
    pass phrase for server.key 与前边输入的必须一致。

    需要输入的信息说明及举例:

    Country Name:ISO国家代码(两位字符),CN
    State or Province Name:所在省份,GuangDong
    Locality Name:所在城市,ShenZhen
    Organization Name:公司名称,KaiKai Technology Co. Ltd.
    Organizational Unit Name:部门名称 IT Dept.
    Common Name:申请证书的域名,test.com
    Email Address:不需要输入
    A challenge password:不需要输入

    请妥善保存生成的文件。

    命令行参数 -config ../conf/openssl.cnf 指出了 ssl 配置文件 openssl.cnf 位置,因为命令行是在bin目录下,openssl.cnf在conf目录下,相对路径必须是两个点,否则报告错误:
    Unable to load config info from /usr/local/ssl/openssl.cnf

    在 Windows 系统下 openssl.cnf 默认会被当成快捷方式,看不到扩展名。

4.提交.csr文件给证书提供商以申请你的域名证书,以便他们制作.crt证书文件和CA文件。
    a、把刚才所生成的 .csr 文件,发给证书提供商。
    b、等待证书提供商颁发证书。
    注:证书提供商目前有VeriSign、globalsign等,自己也可以google下:)

    作为测试。这里自己制作,使用下面的命令:

    Openssl > x509 -in server.csr -out server.crt -req -signkey server.key -days 365
    Loading 'screen' into random state - done
    Signature ok
    subject=/C=CN/ST=shaaanxi/L=xian/O=myCom for Test SSL/OU=my OU name/CN=localhost
    Getting Private key
    Enter pass phrase for server.key:mbi1001

这样就成功生成了证书文件和密钥文件server.crt  server.key  ,放在conf目录下就可以了。

网上找了这么多资料,都非常的乱,把自己都弄晕了,终于配置成功。还有很多不太理解的地方,再慢慢研究!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值