
因为要来回的设置所有直接使用域名 *** 作比如:
chaodiquancom 解析到 IP上面(IP要用你自己的,如果使用CDN另算)
这个是主要在最后的实际应用的测试的使用会用到
因为是自己实际应用,只好从OpenSSL的客户端证书开始学起,一点一点啃,大段大段的E文让我这半瓶子醋看的头晕眼晕。
的提示下终于把这个证书搞定,来秀一个。
这需要一下几个步骤:
1) 安装openssl用来做证书认证
2) 创建一个CA根证书
3) 创建一个自签名的服务器证书
4) 设置Nginx
5) 创建客户端证书
6) 安装客户端证书到浏览器
7) Profit
1)
这一步我是在ubuntu下直接apt-get装的openssl, 配置文件安装在/etc/ssl/opensslcnf
修改opensslcnf的以下几段
[ ca ]
default_ca = foo
Openssl将会寻找名称为foo的配置段
[ foo ]
dir = /etc/ssl/private
database = $dir/indextxt
serial = $dir/serial
private_key = $dir/cakey
certificate = $dir/cacrt
default_days = 3650
default_md = md5
new_certs_dir = $dir
policy = policy_match
policy_match 我保持默认值没有改
[ policy_match ]
countryName = match
stateOrProvinceName = match
organizationName = match
organizationalUnitName = match
commonName = supplied
emailAddress = optional
默认签发有效期为10年,你可以自己设置一个合适的值
2)
创建一个新的CA根证书
下面的几个脚本我都放在/etc/ssl目录下
new_cash:
#!/bin/sh
# Generate the key genrsa意思是生成一个私钥
openssl genrsa -out private/cakey
# Generate a certificate request req表示生成证书,还能生成ca证书,-new表示产生一个新csr,需要输入一些信息,-key表示私钥,
openssl req -new -key private/cakey -out private/cacsr
#
Self signing key is bad this could work with a third party signed
key registeryfly has them on for $16 but I'm too cheap lazy to get
one on a lark
# I'm also not 100% sure if any old certificate will
work or if you have to buy a special one that you can sign with I could
investigate further but since this
# service will never see the light of an unencrypted Internet see the cheap and lazy remark
# So self sign our root key
x509是一个证书生成工具,显示证书内容,转换格式,给CSR签名等
-signkey用来处理CSR和给证书签名,就像CA。使用时得同时提供私钥,把输入文件变成自签名的证书,如果输入CSR文件,则生成自签名文件
-days证书有效时间
-in输入文件 -out输出文件
openssl x509 -req -days 3650 -in private/cacsr -signkey private/cakey -out private/cacrt
#
Setup the first serial number for our keys can be any 4 digit hex
string not sure if there are broader bounds but everything I've seen
uses 4 digits
echo FACE > private/serial
# Create the CA's key database
touch private/indextxt
# Create a Certificate Revocation list for removing 'user certificates'
gencrl在index文件中生成一个CRL相关的信息
-crldays是crl过期的时间
openssl ca -gencrl -out /etc/ssl/private/cacrl -crldays 7
执行 sh new_cash 生成新的CA证书
3)
生成服务器证书的脚本
new_serversh:
#
Create us a key Don't bother putting a password on it since you will
need it to start apache If you have a better work around I'd love to
hear it
openssl genrsa -out private/serverkey
# Take our key and create a Certificate Signing Request for it
openssl req -new -key private/serverkey -out private/servercsr
# Sign this bastard key with our bastard CA key
-cert CA本身的证书名
-keyfile CA本身的私钥
这句就是相当于CA用他的证书和私钥,根据服务器的证书,来给出一个CA认证的证书
openssl ca -in private/servercsr -cert private/cacrt -keyfile private/cakey -out private/servercrt
执行 sh new_serversh 生成新服务器的证书
4)
最要命的一步,尝试多次后终于搞明白。
配置 nginx 的ssl支持
我的配置如下:
# >
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)