

10分钟搞定 Let’s Encrypt 泛域名 SSL 证书
source link: https://www.bluesdream.com/blog/letsencrypt-extensive-domain-name-ssl-certificate.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

之前域名都是用的 阿里云盾证书服务
,因为是一起申请,所以每年更新一下问题不大。
虽然 Let's Encrypt
在免费SSL证书里能说是最有人气(最大因素在于支持 泛域名
),但以前需要每3个月手工更新一次,虽有自动更新可不够稳定,如果不注意就比较尴尬。
而现在 acme.sh
已经比较成熟,很好解决了自动续期问题。最近加两个子域名,又正好下月 SSL证书
到期,借此契机换成 Let's Encrypt
证书。
并且国内的 云盾证书服务
都会有申请限制,就拿阿里云的说明为例: 个人型SSL证书,保护一个域名。浏览器上有https提示并有绿锁标记。快速签发,适合个人和小微企业,支持个人/企业申请。一个阿里云帐户最多签发20张。
我们来划下重点 一个阿里云帐户
、 最多
、 20张
,也就是一个正好终身只能申请20次,域名/子域多的话,还是消耗的挺快。
有关阿里云的 SSL证书
的介绍和安装,可以查看我之前的文章: 《阿里云 免费SSL证书安装小记》
操作步骤:
acme.sh
只要简单的6步操作,即可完成。
一、登陆阿里云
# 登陆阿里云 ssh root@SeverIp
普通用户和 root 用户都可以
二、安装 acme.sh
# 执行安装命令 `curl https://get.acme.sh | sh`
执行成功后会自动安装到:~/.acme.sh/
如果遇到以下错误提示,需要先安装 socat
依赖包 yum install socat -y
再执行安装命令。
# 错误信息: ······ [2020年 03月 15日 星期五 23:19:10 CST] It is recommended to install socat first. [2020年 03月 15日 星期五 23:19:10 CST] We use socat for standalone server if you use standalone mode. [2020年 03月 15日 星期五 23:19:10 CST] If you don't use standalone mode, just ignore this warning. ······
三、导入密钥
acme.sh
目前支持 cloudflare
, dnspod
, cloudxns
, godaddy
以及 ovh
等数十种解析商的自动集成。可以使用域名解析商提供的 api 自动添加 txt 记录完成验证。
密钥只需导入一次即可,根据你所使用的域名解析服务商而定,本文提供 DNSPod
和 AliYun
2个导入方式。
DNSPod 域名解析
由于我是使用的是 DNSPod
解析服务,那就登录 DNSPod
官网生,成所需的 api id
和 api key
。
操作方法:点击右上角头像 -> 我的账号 -> 账号中心 -> 密钥管理 -> 创建密钥
然后执行导入命令:
# DNSPod export DP_Id="YourID" export DP_Key="YourKey"
PS:创建密钥具体位置,可能随网站改版而略有调整
万网/阿里云 域名解析
如果你是使用 万网/阿里云
的 NDS 解析:
操作方法:点击右上角头像 -> 选择 AccessKey
-> 点击 开始使用子用户AccessKey
-> 起个自定义名称 -> 搜索 NDS
-> 选择 系统 AliyunDNSFullAccess
然后执行导入命令:
# AliYun export Ali_Key="YourKey" export Ali_Secret="YourSecret"
四、生成证书(签发通配符证书)
# 执行以下命令 acme.sh --issue --dns dns_dp -d *.YourDomain.com
# 命令执行成功后的显示 [2020年 03月 15日 星期五 23:19:10 CST] Creating domain key ······ [2020年 03月 15日 星期五 23:19:10 CST] The txt record is added: Success. [2020年 03月 15日 星期五 23:19:10 CST] Let's check each dns records now. Sleep 20 seconds first. ······ [2020年 03月 15日 星期五 23:19:10 CST] Pending [2020年 03月 15日 星期五 23:19:10 CST] Pending [2020年 03月 15日 星期五 23:19:10 CST] Pending [2020年 03月 15日 星期五 23:19:10 CST] Pending [2020年 03月 15日 星期五 23:19:10 CST] Success ······ [2020年 03月 15日 星期五 23:19:10 CST] Verify finished, start to sign. ······ [2020年 03月 15日 星期五 23:19:10 CST] Cert success.
最后看到 Cert success
表示申请成功
证书会存放在 ~/.acme.sh/*.YourDomain.com/
五、证书拷贝到 Nginx
# 执行以下命令 acme.sh --installcert -d *.YourDomain.com \ --key-file /Nginx目录/存放证书的目录/key名称.pem \ --fullchain-file /Nginx目录/存放证书的目录/cert名称.pem \ --reloadcmd "service nginx force-reload"
--installcert 命令至关重要,当证书更新以后, reloadcmd 会被自动调用,让服务器生效。
目前证书在 60 天以后会自动更新,无需任何操作。
# 命令执行成功后的显示 [2020年 03月 15日 星期五 23:19:10 CST] Installing key to:/Nginx目录/存放证书的目录/key.pem [2020年 03月 15日 星期五 23:19:10 CST] Installing full chain to:/Nginx目录/存放证书的目录/cert.pem [2020年 03月 15日 星期五 23:19:10 CST] Run reload cmd: service nginx force-reload Redirecting to /bin/systemctl force-reload nginx.service [2020年 03月 15日 星期五 23:19:10 CST] Reload success
六、配置 Nginx
修改 Nginx 配置,将 ssl_certificate
和 ssl_certificate_key
指向新证书存放位置。
server { listen 443; // ······ // 修改证书路径 ssl_certificate 存放证书的目录/cert名称.pem; ssl_certificate_key 存放证书的目录/key名称.pem; // ······ }
如果你是初次安装 SSL证书,别忘记设置 301跳转
,把 HTTP 指向 HTTPS。
参考资料
Recommend
-
10
From our blog Nov 6, 2020 Standing on O...
-
12
使用Let's Encrypt创建SSL证书 TianFang 相濡以沫,不如相忘于江湖 随笔 - 824 文章 - 5 评论 - 923 阅读 - 396...
-
9
Let's Encrypt SSL certificate overview Overview Let's Encrypt is a new Certificate Authority (CA) that offers FREE SSL certificates that are just as secure as paid...
-
13
免费SSL证书Let's Encrypt的替代:SSL.com随着 HTTPS 在 Web 上的使用不断增加,我们需要颁发证书的证书颁发机构提供更多支持,Let's Encrypt提供的免费SSL证书,但如果我们想加密整个 Web,我们不能依...
-
9
V2EX › 程序员 练手撸了个 Let's encrypt 的 SSL 证书签发服务 neurocomputing ·...
-
9
Configuring NGINX for SSL with Let's Encrypt By Joel Berger o...
-
7
Using a Different System? Let...
-
5
Using a Different System? Let...
-
7
Not FoundYou just hit a route that doesn't exist... the sadness.LoginRadius empowers businesses to deliver a delightful customer experience and win customer trust. Using the LoginRadius Identity...
-
9
Let's Encrypt 如何配置Let's Encrypt SSL证书 Web进行安全通信依赖于HTTPS,这需要使用数字证书,以便浏览器验证Web服务器的身份,比如说...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK