安装Certbot
Certbot是一个自动生成Let’s Encrypt免费SSL证书的自由开源工具。CentOS可以通过yum直接安装:
1 | yum install certbot |
获取Cloudflare API Key
因为DNS解析是托管在CloudFlare上,通过DNS API去验证域名所有权并申请/更新证书操作起来更简单。
在CloudFlare个人资料里获取Global API Key,在VPS上创建cf.ini
文件填入帐号和Key:
1 | # Cloudflare API credentials used by Certbot |
申请证书
用DNS插件申请域名和二级域名的证书:
1 | certbot certonly -d 'yourdomain.com' -d '*.yourdomain.com' \ |
证书默认会保存在/etc/letsencrypt/live/yourdomain.com
目录下面。
配置Nginx
配置/etc/nginx/nginx.conf
:
1 | server { |
重启Nginx就对所有二级域名都生效了。可以到SSL Labs检测一下SSL评分是不是A+。
证书续期
证书有效期为90天,所以需要定期更新,离过期30天以内可以续期,续期命令(可以加--dry-run
试一下):
1 | certbot renew \ |
可以写个crontab定时任务每个月执行一次:
1 | 55 7 1 * * /usr/bin/certbot renew --dns-cloudflare --dns-cloudflare-credentials /etc/nginx/cf.ini --dns-cloudflare-propagation-seconds 60 >> ~/cert.log && systemctl restart nginx |
-
本文作者:
Shintaku
本文链接:
https://www.shintaku.xyz/posts/certbot-ssl/
版权声明:
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Shintaku's Blog 。