Let's Encrypt 通配符证书免费申请自动续期

Published on 03 August 2020 By. ghost

什么是 Let’s Encrypt?

file

Let’s Encrypt是一个由非营利性组织互联网安全研究小组(ISRG)提供的免费、自动化和开放的证书颁发机构(CA)。

简单的说,借助Let’s Encrypt颁发的证书可以为我们的网站免费启用HTTPS(SSL/TLS) 。

Let’s Encrypt免费证书的签发/续签都是脚本自动化的,官方提供了几种证书的申请方式方法,点击此处快速浏览。

官方推荐使用Certbot客户端来签发证书。

如何申请 Let’s Encrypt 通配符证书

为了实现通配符证书,Let’s Encrypt 对 ACME 协议的实现进行了升级,只有 v2 协议才能支持通配符证书。

也就是说任何客户端只要支持 ACME v2 版本,就可以申请通配符证书了。

下载certbot-auto

$ wget https://dl.eff.org/certbot-auto  
$ chmod a+x  certbot-auto 
$ ./certbot-auto --version
Requesting to rerun ./certbot-auto with root privileges...
./certbot-auto has insecure permissions!
To learn how to fix them, visit https://community.letsencrypt.org/t/certbot-auto-deployment-best-practices/91979/
certbot 1.6.0

申请通配符证书脚本

https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au

$ git clone https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au

$ cd certbot-letencrypt-wildcardcertificates-alydns-au

$ chmod 0777 au.sh

到期定时续费脚本

这里的脚本是nginx 编译安装或者通过docker 安装的服务器 通过宿主机代理 或者负载均衡主机代理https

自动备份ssl证书 重启nginx代理服务器

注:脚本实际使用的依然是 ./certbot-auto renew

#!/usr/bin/env bash

cmd="$HOME/certbot-auto" 
restartNginxCmd="docker restart ghost_nginx_1"
action="renew"
auth="$HOME/certbot/au.sh php aly add"
cleanup="$HOME/certbot/au.sh php aly clean"
deploy="cp -r /etc/letsencrypt/ /home/pi/dnmp/services/nginx/ssl/ &&  $restartNginxCmd"

$cmd $action \
     --manual \
     --preferred-challenges dns \
     --deploy-hook  \
     "$deploy"\
     --manual-auth-hook \
     "$auth" \
     --manual-cleanup-hook \
     "$cleanup"

加入 crontab

编辑文件 /etc/crontab :

#证书有效期<30天才会renew,所以crontab可以配置为1天或1周
#   0 0 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && /home/pi/crontab.sh
0条评论

发表评论

您的电子邮件地址不会被公布。必填字段被标记为*