acme.sh使用阿里云DNS申请Let’s Encrypt的https证书

acme.sh使用阿里云DNS申请Let’s Encrypt的https证书,第1张

环境:

        centos7

前置条件:

        域名一个

        acme 脚本

        阿里云云账号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离线包 。


# 安装
$ 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!

# 让环境变量生效
$ source ~/.bashrc

        crontab 定时任务报错:crontab -e    然后 保存下退出。


估计是新账户并没有crontab文件。


        尝试指定默认的ca机构: acme.sh --set-default-ca --server letsencrypt。


        2. 生成证书

                记得将 example.com 替换为你自己的域名。


export Ali_Key="xxx" && export Ali_Secret="xxx"

# 因为生成的通配符域名证书中并不包含根域名证书,所以我们要指定根域名。


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 . . . # 创建放置证书的文件夹 mkdir -p /data/certs/com.example/ # 前面证书生成以后,,需要把证书 copy 到真正需要用它的地方。


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:该域名证书的私钥 

测试:

        安装node.js 后,运行: node index.js

        测试时需要手动设置 hosts文件: 

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)

引用:

中文说明 · 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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/567653.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存