记录下certbot生成letsencrypt通配符证书

现在好多站点都会启用https了,因为七牛给的免费CDN一直都在用,但是免费的只支持http,所以我并没有全站都切https。但是有时候会部署一些其他的服务,如果每次都申请证书也很麻烦,因此就考虑用certbot来申请通配符证书。

还是用的Ubuntu 18.04的服务器,如果使用apt-get安装的certbot版本会太低,导致不能申请对应的通配符证书,因此需要使用pip3安装:

pip3 install certbot
pip3 install certbot-apache
pip3 install certbot-dns-standalone
apt install libaugeas0 # 执行会依赖这个库,因此也需要安装下

安装完成后,执行以下的命令,来生成通配符证书:

certbot certonly --preferred-challenges dns --manual -d elkpi.com -d *.elkpi.com --server https://acme-v02.api.letsencrypt.org/directory

之后会提示需要配置DNS TXT,配置好之后,才按回车下一步,这样就可以完成对应的申请了。但是使用pip安装也有一个缺点,就是没有对应的systemd服务来执行重新申请证书的定期操作,因此可以自己加一下两个systemd服务:

certbot.timer

[Unit]
Description=Twice daily renewal of Let's Encrypt's certificates

[Timer]
OnCalendar=0/12:00:00
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target

certbot.service

[Unit]
Description=Let's Encrypt renewal

[Service]
Type=oneshot
ExecStart=/usr/local/bin/certbot renew --quiet --agree-tos
ExecStartPost=/bin/systemctl reload apache2.service
ExecStartPost=/bin/systemctl restart frps.service

ExecStartPost=/bin/systemctl reload apache2.service # 如果用来做Apache的证书,那么renew新证书,则reload Apache服务,如果是其他的一些服务,也可以自己修改对应的ExecStartPost,多个服务则可以多个ExecStartPost的实例即可(比如我上面还有用于frps的支持,因此也设置了下需要重启frps)。

转载请注明: 转载自elkPi.com

本文链接地址: 记录下certbot生成letsencrypt通配符证书

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Scroll to top