AWS ACM SSL 证书导入到Nginx的曲折过程
最近在配置亚马逊 AWS 上面的一个Web 服务器, 需要配置SSL数字证书, 在搞定了域名、域名验证等一系列问题之后,终于成功申请了一个数字证书, 花费了15 美刀。 注意的是, 在AWS 中, SSL 数字证书是分为两种, 可以导出文件的,以及只能在AWS 中配置、不可导出的数字证书。 不可导出的数字证书是不要钱的,但是我这里需要在EC2的Nginx 中使用,因此只能选择导出类型的数字证书。
导出数字证书之后, 感觉有点不对劲。 我以前都是在阿里云请求数字证书, 阿里云做的还不错, 可以根据需要产生pem 或者JKS 证书, 导出的文件能直接部署, 但是AWS ACM 这里是不行的, ACM 会产生三个文件: certification、chained certification 和private-key.txt , 虽然从格式上讲,这三个文件都是pem 格式的文件,只是后缀名不同,但是这三个文件明显和我已有的阿里云的经验不同啊~~
配置到nginx 之上, 果然就出问题了, 打开error log 仔细一看,是这样的:
[emerg] 29213662921366: cannot load certificate key "cert/private.key": PEM_read_bio_PrivateKey() failed (SSL: error:1400006B:UI routines::processing error:while reading strings error:0480006D:PEM routines::problems getting password error:07880109:common libcrypto routines::interrupted or cancelled error:07880109:common libcrypto routines::interrupted or cancelled error:1C80009F:Provider routines::unable to get passphrase error:1400006B:UI routines::processing error:while reading strings error:0480006D:PEM routines::problems getting password error:07880109:common libcrypto routines::interrupted or cancelled error:04800068:PEM routines::bad password read)
啥意思呢, 就是这个默认的key 文件是设置了一个password phrase, 这个也是ACM 页面导出证书的时候必须要指定的, 不设置这个密码就不能导出三个证书文件。
那怎么改呢, 也很简单,一个语句:
openssl rsa -in key.pem -out newkey.pem
我这里用的是椭圆曲线,因此用这条命令:
openssl ec -in key.pem -out newkey.pem
去掉密码之后, nginx 终于启动起来了!
简单的修改背后,是无数的尝试, 哎~~累啊~~