设置apache https服务

  • 配置http.conf,所在位置d:\wamp\bin\apache\apache2.4.9\conf\http.conf
 
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule sslmodule modules/modssl.so
Include conf/extra/httpd-ssl.conf
 
  • 配置http-ssl.conf,所在位置d:\wamp\bin\apache\apache2.4.9\conf\extra\http-ssl.conf
 
# 注意路径都改到wamp的目录下
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLSessionCache "shmcb:E:/wamp/logs/ssl_scache"
DocumentRoot "d:/wamp/www"
ServerName localhost:443
ErrorLog "d:/wamp/logs/apache_error.log"
TransferLog "d:/wamp/logs/access.log"
 
SSLCertificateFile "d:/wamp/bin/apache/apache2.4.9/bin/server.crt"
SSLCertificateKeyFile "d:/wamp/bin/apache/apache2.4.9/bin/server.key"
SSLCACertificateFile "d:/wamp/bin/apache/apache2.4.9/bin/ca.crt"
 
# 要求进行客户端认证,如果是双向认证,需要打开
SSLVerifyClient require        
SSLVerifyDepth  1
 
CustomLog "d:/wamp/logs/ssl_request.log"
 
  • 生成证书
# openssl程序,在wamp\bin\apache\apache2.4.9\bin目录下
 
生成私钥
openssl> genrsa -out ca.key 2048
openssl> genrsa -out server.key 2048
openssl> genrsa -out client.key 2048
 

自签署ca证书

openssl> req -x509 -new -key ca.key -out ca.crt -config ../conf/openssl.cnf -days 365
 
# 因为是根证书,这里的Common Name只填显示名称即可
 
说明:
Country Name 国家代码(只支持两位字符)
Province Name 省份
Locality Name 城市
Organization Name 公司名称
Organizational Unit Name 组织名称
Common Name (申请证书的域名或IP地址)  
Email Address 管理员邮箱  
 

服务端申请签署资料生成

 
req -new -key server.key -out server.csr -config ../conf/openssl.cnf -days 365
 
# 需注意国家、省、市这些资料,必需和根证书CA一样,不然没法用CA签证
# Common Name为当前服务器IP或域名
 
客户端申请签署资料生成
req -new -key client.key -out client.csr -config ../conf/openssl.cnf -days 365
 
建立CA自签目录
wamp\bin\apache\apache2.4.9\bin目录下
 
mkdir -p ./demoCA/newcerts
touch ./demoCA/index.txt
echo 01 > ./demoCA/serial
echo 01 > ./demoCA/crlnumber
 
 

用ca证书给服务端签名

 
ca -in server.csr -cert ca.crt -keyfile ca.key -out server.crt  -config ../conf/openssl.cnf
 
# 注意生成之后,需要清空demoCA/index.txt里面的内容,不然给下一个签证时会报错
 
 

用ca证书给客户端签名

 
ca -in client.csr -cert ca.crt -keyfile ca.key -out client.crt  -config ../conf/openssl.cnf
 
 

生成客户端使用证书

 
pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.pfx
 
--------------------------------------
  • 测试使用
 
 
因为证书不是机构所发,所以会提示这个
 
  • 导入CA根证书
此时访问就ok了
posted @ 2016-01-06 15:38  Athrun  阅读(430)  评论(0编辑  收藏  举报