ssl 证书申请

https(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的 http 通道,简单讲是 http 的安全版。即 http 下加入 SSL 层,https 的安全基础是 SSL,所以加密的详细内容就须要 SSL。在各个 Linux 发行版中,实现 SSL 的通常则是 openssl 套件。

html

一、生成证书请求 CSR 文件node

这里须要用到 openssl 命令,须要安装 openssl。git

yum install -y openssl openssl-devel

以 RSA 2048 私钥举例,命令以下:github

openssl req -new -nodes -newkey rsa:2048 -sha256 -keyout server.pem -out server.csr

以 ECC 256 私钥举例,命令以下:安全

openssl ecparam -out server.pem -name prime256v1 -genkey
openssl req -new -key server.pem -out server.csr

以上命令,在生成 CSR 的时候会有个交互,以下:dom

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) [XX]:CN  // 国家代码
State or Province Name (full name) []:Shanghai  //
Locality Name (eg, city) [Default City]:Shanghai  //
Organization Name (eg, company) [Default Company Ltd]:Teddysun // 组织或公司名(随便填)
Organizational Unit Name (eg, section) []:  // 部门,可不填
Common Name (eg, your name or your server's hostname) []:teddysun.com // *则是通配符域名,通常证书发行会自带 www 子域名
Email Address []:admin@teddysun.com  // 邮箱地址(必定要有个域名邮箱,用以验证域名全部权)

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:  // 不填
An optional company name []:  // 不填

注意:
这里的 server.pem 即为私钥,须要好好保存,最好你申请下来的证书在配置时,须要用到这个私钥,一旦私钥丢失,该证书就废了,只能从新申请。
通常状况下,申请 RSA 2048 的证书就足够了。编辑器

以上步骤所有作完,则会生成两个文件:
server.pem
server.csrui

将其下载回本地,妥善保管。用任意文本编辑器打开 server.csr,用里面的内容去申请证书便可。加密

固然,最好是将这 2 个文件更名为你本身的域名,以方便辨识,好比:spa

example.com.pem
example.com.csr

 

二、申请证书

如今市面上应该已经存在多种免费 SSL(DV)的提供商:
1)letsencrypt (https://github.com/certbot/certbot
2)startssl  (https://www.startssl.com/
3)wosign  (https://buy.wosign.com/free/
4)comodo
5)alphassl
前 3 种都比较容易申请,后 2 种则须要经过一些途径才能免费获取的到。付费的则五花八门了,这里就再也不赘述。申请过程省略。申请成功后,你会获得一个证书文件(通常后缀名为 crt)。

注意:
有的证书(好比 comodo 及 alphassl)还须要合并证书链,将你获得的证书以及根证书合并到同一个文件中才能使用。每家的证书链都是不同的,若是你是用 letsencrypt 申请的话,默认已是有个完整证书链的证书了。
/etc/letsencrypt/live/<domain>/fullchain.pem

Tips:如何合并证书链?
用任意文本编辑器打开你的证书文件(好比名称为:teddysun_com.crt),在文本的最后面添加根证书(teddysun_com.ca-bundle)里的所有内容,保存。

 

原文路径: https://teddysun.com/454.html