一 、 可以下载与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) []:localhostEmail 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目录下就可以了。
网上找了这么多资料,都非常的乱,把自己都弄晕了,终于配置成功。还有很多不太理解的地方,再慢慢研究!