引言
关于certbot
Certbot is a free, open source software tool for automatically using Let’s Encrypt certificates on manually-administrated websites to enable HTTPS.
Certbot is made by the Electronic Frontier Foundation (EFF), a 501(c)3 nonprofit based in San Francisco, CA, that defends digital privacy, free speech, and innovation.
简单来说就是可以为自己的测试服务器提供免费的ssl证书,下面简单记录一下使用方法。
安装certbot
ubuntu
sudo apt update
sudo apt install certbot
centos
sudo yum install epel-release
sudo yum install certbot
使用certbot生成证书
certbot命令执行后即可产生证书,但是需要验证才可以使用,一般验证有两种方式,一个是使用dns记录验证,命令执行后会得到一串hash码,以对应的域名,此时在公网的dns配置上增加一个对应的a记录即可。还有一个方法是使用nginx验证
证书生成命令:
sudo certbot certonly --webroot -w /var/www/html -d yourdomain.com
执行命令后会输入一些邮箱信息,然后会得到下图类似的dns验证信息,需要在公网增加对应的a记录来验证。
也可以通过配置nginx访问来验证,如在对应域名的域名路径下,增加一个访问文件,值是图中的hash值即可。
完成之后就会得到类似下图的说明,会将生成的文件保存在以下路径中,后续的ssl配置访问使用对应文件即可。
自动续期
可以在crontab中增加如下的定时任务来进行自动续期,需要注意域名以及,如果没有到期是没法自动续期的,也就是每90天才能续期一次。
sudo certbot renew --webroot -w /var/www/html --cert-name yourdomain.com
后记
certbot对于测试用ssl是非常简单易用的,但是验证方式有时候会忘记,所以于此记录一下。
文档信息
- 本文作者:Mikatsuki
- 本文链接:https://akitozz.github.io/2025/03/29/certbot/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)