acme.sh使用阿里云DNS申请Let’s Encrypt的https证书
環境:
????????centos7
前置條件:
? ? ? ? 域名(在阿里云購買一個最低的域名即可)
????????acme 腳本
???????阿里云云賬號AccessKey ID和AccessKey Secret(參考阿里云官方文檔進行申請)如何獲取阿里云云賬號AccessKey ID和AccessKey Secret - 阿里云,如下圖:
? ? ?
前言:
acme.sh? 有兩種方式驗證: http 和 dns 驗證。
????????1. http 方式需要在你的網站根目錄下放置一個文件, 來驗證你的域名所有權,完成驗證. 然后就可以生成證書了.(需要公網IP和開放相應端口)
????????2. 手動 dns 方式, 手動在域名上添加一條 txt 解析記錄, 驗證域名所有權.以阿里云為例,你需要先登錄到阿里云賬號,生成你自己的 api id 和 api key,它是免費的 (建議開啟阿里云【RAM 訪問控制】,只給 AliyunDNSFullAccess 權限策略,這樣做更安全)。
這里采用不需要公網IP 的 DNS驗證。
安裝配置:
? ? ? ? 1、安裝 acme.sh ,如果curl失敗,可以使用?acme離線包?。
# 安裝 [admin@instance-20]$ curl https://get.acme.sh | sh . . . [Sat Mar 16 18:22:28 CST 2019] Good, bash is found, so change the shebang to use bash as preferred. [Sat Mar 16 18:22:29 CST 2019] OK [Sat Mar 16 18:22:29 CST 2019] Install success!# 使環境變量生效 [admin@instance-20]$ source ~/.bashrc? ? ? ? crontab 定時任務報錯:crontab -e? ? 然后 保存下退出。估計是新賬戶并沒有crontab文件。
? ? ? ? 嘗試指定默認的ca機構:?
????????????????acme.sh --set-default-ca --server letsencrypt
????????2. 生成證書
? ? ? ? ? ? ? ? 記得將?example.com 替換為你自己的域名。
? ? ? ? ? ? ? ? acme.sh 路徑地址:? ? ?
????????????????????????/home/admin/.acme.sh
[admin@instance-20]$ export Ali_Key="xxx" && export Ali_Secret="xxx"# 因為生成的通配符域名證書中并不包含根域名證書,所以我們要指定根域名。 [admin@instance-20]$ acme.sh --issue --dns dns_ali -d example.com -d *.example.com . . . [Mon Mar 25 11:28:48 CST 2019] Your cert is in /home/user/.acme.sh/example.com/example.com.cer [Mon Mar 25 11:28:48 CST 2019] Your cert key is in /home/user/.acme.sh/example.com/example.com.key [Mon Mar 25 11:28:48 CST 2019] The intermediate CA cert is in /home/user/.acme.sh/example.com/ca.cer [Mon Mar 25 11:28:48 CST 2019] And the full chain certs is there: /home/user/.acme.sh/example.com/fullchain.cer . . .# 創建放置證書的文件夾 [admin@instance-20]$ mkdir -p /data/certs/com.example/# 前面證書生成以后,,需要把證書 copy 到真正需要用它的地方。 # 這里是Nginx的配置方法 [admin@instance-20]$ acme.sh --install-cert -d example.com -d *.example.com \ --key-file "/data/certs/com.example/com.example.key" \ --fullchain-file "/data/certs/com.example/fullchain.cer" \ --reloadcmd "service nginx force-reload"相關文件的用途如下:
- ca.cer:Let’s Encrypt的中級證書
- fullchain.cer:包含中級證書的域名證書
- m4d3bug.com.cer:無中級證書的域名證書
- m4d3bug.com.conf:該域名的配置文件
- m4d3bug.com.csr:該域名的CSR證書請求文件
- m4d3bug.com.csr.conf:該域名的CSR請求文件的配置文件
- m4d3bug.com.key:該域名證書的私鑰?
測試:
? ? ? ?1- 將下面文本保存為?index.js
const https = require('https') const fs = require('fs')const options = {key: fs.readFileSync('D:\\Desktop\\com.example.key'),cert: fs.readFileSync('D:\\Desktop\\fullchain.cer')}https.createServer(options, (req, res) => {res.writeHead(200)res.end('hello work\n')}).listen(8000)? ? ? ? 2-安裝node?后,運行: node index.js
? ? ? ? 3-如果使用域名則需要配置手動設置 hosts文件。
Linux下定時續簽(每月1,15日 12:30分自動續簽一次):? ? ? ?
# 定時任務自動續簽[root@ins125-1102 ~]# crontab -e30 12 1,15 * * /home/admin/.acme.sh/acme.sh --cron --home "/home/admin/.acme.sh"# 手動續簽證書 [root@ins125-1102 ~]# /home/admin/.acme.sh/acme.sh --cron --home "/home/admin/.acme.sh" [Fri Jun 17 00:32:12 CST 2022] ===Starting cron=== [Fri Jun 17 00:32:12 CST 2022] Renew: 'zxxsi.top' [Fri Jun 17 00:32:12 CST 2022] Skip, Next renewal time is: Mon May 15 15:48:54 UTC 2022 [Fri Jun 17 00:32:12 CST 2022] Add '--force' to force to renew. [Fri Jun 17 00:32:12 CST 2022] Skipped zxxsi.top [Fri Jun 17 00:32:12 CST 2022] ===End cron===引用:
中文說明 · acmesh-official/acme.sh Wiki · GitHub
https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E
使用acme.sh與阿里云DNS簽發Let’s Encrypt的免費數字證書 | NGX Project | NGX.HK
https://ngx.hk/2019/01/27/%E4%BD%BF%E7%94%A8acme-sh%E4%B8%8E%E9%98%BF%E9%87%8C%E4%BA%91dns%E7%AD%BE%E5%8F%91lets-encrypt%E7%9A%84%E5%85%8D%E8%B4%B9%E6%95%B0%E5%AD%97%E8%AF%81%E4%B9%A6.html
在anyconnect中使用可信SSL證書(Let's Encrypt) - outs,網絡資源 - 宅...orz
https://zorz.cc/post/anyconnect-with-trusted-ssl.html
使用acme.sh簽發數字證書的疑問_AllenLeungX的博客-CSDN博客
https://blog.csdn.net/londa/article/details/91362000
使用Let's Encrypt免費證書實現https - 知乎
https://zhuanlan.zhihu.com/p/143442969
申請Let's Encrypt永久免費SSL證書 - DF的翱翔 - 博客園
https://www.cnblogs.com/sage-blog/p/10302934.html
SignatureNonceUsed, 怎么解決_API錯誤碼 - 阿里云API錯誤中心
https://error-center.aliyun.com/status/search?Keyword=SignatureNonceUsed
總結
以上是生活随笔為你收集整理的acme.sh使用阿里云DNS申请Let’s Encrypt的https证书的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 几个不错的开源BPM系统
- 下一篇: 1527发码函数