在这一章节里, 我记录了一下如何在 wamp 环境下配置 ssl

前提条件

在设置 Apache + SSL 之前, 需要确认 Apache 已经安装并可以正常工作. 并且 ssl 需要的文件在如下的位置:

1
2
3
4
5
[Apache安装目录]/modules/ mod_ssl.so
 
[Apache安装目录]/bin/ openssl.exe, libeay32.dll, ssleay32.dll
 
[Apache安装目录]/conf/ openssl.cnf

配置文件修改

1
2
3
//去掉下面行首的 # 号
#LoadModule ssl_module modules/mod_ssl.so
#Include conf/extra/httpd-ssl.conf

用于载入 ssl 模块和其配置文件

认证文件生成

在命令行下进入Apache安装目录下\bin文件夹,输入命令:

1
2
3
//生成证书签发请求
 
D:\wamp\apache\bin> openssl req -new -out server.csr -config ../conf/openssl.cnf
1
2
3
4
5
6
7
8
9
10
//回车后要求输入密码和确认密码
 
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
......................................................................++++++
........................................++++++
writing new private key to 'privkey.pem'
Enter PEM pass phrase: 123456
Verifying - Enter PEM pass phrase: 123456
-----
1
2
3
4
5
6
7
8
9
10
//确认密码输完回车后, 要求输入国家缩写, 只能2个字母
 
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
1
2
3
//要求输入州名或省名
 
State or Province Name (full name) [Some-State]:Shanghai
1
2
3
//要求输入城市名
 
Locality Name (eg, city) []:Shanghai
1
2
3
//要求输入组织名或者公司名
 
Organization Name (eg, company) [Internet Widgits Pty Ltd]:yiban
1
2
3
//要求输入部门名
 
Organizational Unit Name (eg, section) []:yiban
1
2
3
//要求输入服务器域名或IP地址
 
Common Name (e.g. server FQDN or YOUR name) []:yiban
1
2
3
//要求输入邮件地址
 
Email Address []:shawn0828@hotmail.com
1
2
3
4
5
//要求输入密码
 
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
1
2
3
//要求输入公司别名
 
An optional company name []:yiban
1
2
3
//生成私钥,输入命令:
 
D:\wamp\apache\bin>openssl rsa -in privkey.pem -out server.key
1
2
3
4
//要求输入之前 privkey.pem 的密码
 
Enter pass phrase for privkey.pem: 123456
writing RSA key
1
2
3
//创建证书,输入命令:
 
D:\wamp\apache\bin>openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 8000
1
2
3
4
5
6
7
//回车后, 显示创建成功, 有效期为 8000 天
 
Loading 'screen' into random state - done
Signature ok
subject=/C=CN/ST=Shanghai/L=Shanghai/O=yiban/OU=yiban/CN=yiban/emailAddress=shaw
n0828@hotmail.com
Getting Private key

完成后, 将 \bin 下面的 server.csr、server.crt、server.key 拷贝到 [Apache安装目录]\conf\ssl 文件夹中, 没有则创建

再打开 [Apache安装目录]\conf\extra\httpd-ssl.conf 文件
替换 SSLCertificateFile 和 SSLCertificateKeyFile 语句对应的路径,例:

1
2
3
4
#SSLCertificateFile "D:/wamp/apache/conf/server.crt" //配置文件默认内容
 
//替换为
SSLCertificateFile "D:/wamp/apache/conf/ssl/server.crt"
1
2
3
4
#SSLCertificateKeyFile "D:/wamp/apache/conf/server.key" //配置文件默认内容
 
//替换为
SSLCertificateKeyFile "D:/wamp/apache/conf/ssl/server.key"

最后, 重启 Apache 服务器

2013的某一天

在重启 Apache 时,若遇到 Apache 无法运行的情况

1
2
可以运行开始菜单中 Apache HTTP Server 2.2\Configure Apache Server\Test Configuration
来查找 httpd.conf 中的详细错误情况
1
或通过查看 Apache 安装目录下的 logs 文件夹内的 access.log 和 error.log 中的记录解决问题

如有更好的建议和代码片段,欢迎留言提出

最新文章

  1. CSS轮廓outline
  2. iOS 学习 - 10下载(2) NSURLSession 图片 篇
  3. nginx location在配置中的优先级
  4. IOS第18天(6,CAKeyframeAnimation关键帧动画)
  5. [简单]docx4j常用方法小结
  6. 269. Alien Dictionary
  7. JUnit使用参数测试和一组测试
  8. Entity Framework Core 命名约定
  9. Linaro系统获取root权限方法
  10. awk 里的substr()
  11. Android4.2.2源码目录结构分析
  12. 数据库MySQL——初识
  13. 好程序员分享Javascript设计模式
  14. 2018 Multi-University Training Contest 3 杭电多校第三场
  15. mysql系列九、mysql语句执行过程及运行原理(分组查询和关联查询原理)
  16. equals 与 == 的区别
  17. 转:sql语句优化
  18. JIRA 的字段配置
  19. 001.開始使用ASP.NET Web API 2(一)
  20. Uncaught SyntaxError: Invalid shorthand property initializer

热门文章

  1. ansible usually
  2. php libevent扩展的简单用例
  3. 《Python数据分析与挖掘实战》-第四章-数据预处理
  4. ZooKeeper伪集群的搭建(Windows)
  5. 让SSL证书给服务器上一把“锁”
  6. HDU1867 - A + B for you again
  7. flask_sqlalchemy和sqlalchemy联系区别及其使用方式
  8. Ubuntu18.04 安装 oh-my-zsh
  9. Linux目录结构组成
  10. PHP算法之判断是否是质数