LetsEncrypt是一项为用户提供免费的SSL / TLS证书的服务。 Certbot是使它易于完成和自动化的客户端。此外,它还具有适用于Apache和Nginx的插件,使证书生成的自动化更加容易。
可以在Certbot网站上找到大多数Linux发行版的安装说明。

安装软件包后,即可准备生成新证书。
阿帕奇
安装Certbot和Apache插件后,可使用以下命令完成证书的生成。
certbot certonly --apache --noninteractive --agree-tos-通过电子邮件发送YOUR_EMAIL -d DOMAIN_NAME
更新“ SSLCertificateFile”和“ SSLCertificateKeyFile”部分,然后重新启动服务。
将作业添加到cron,以便自动更新证书。
回显“ 0 0 * * * root certbot更新--quiet --no-self-upgrade --post-hook $0027systemctl reload apache2$0027” | sudo tee -a /etc/cron.d/renew_certbot
HAProxy
HAProxy当前没有Certbot插件。为避免这种情况,请以独立模式运行Certbot并通过网络代理流量。
在上述配置中启用前端和后端,然后运行Certbot。
certbot certonly --standalone --preferred-challenges http-01 --http-01-port 8888 --noninteractive --agree-tos-通过电子邮件发送YOUR_EMAIL -d DOMAIN_NAME
可以将端口更改为所需的任何端口,但请确保HAProxy设置和Certbot命令匹配。
HAProxy需要在同一文件中拥有证书和串联的密钥文件,以便正确读取它。这可以通过以下命令来完成。
猫/etc/letsencrypt/live/domain/name/fullchain.pem /etc/letsencrypt/live/domain/name/privkey.pem分解设置中的bind *:443和redirect部分,然后重新加载服务。
自动续订证书
将以下脚本放在/ usr / local / bin /中,以自动更新SSL证书。
SITE = DOMAIN_NAME#传递到正确的目录,我们将加密目录cd / etc / letsencrypt / live / $SITIO#猫文件,以便为haproxycat fullchain.pem privkey.pem> /etc/ssl/$SITIO.pem1TPxer重新加载确保脚本是可执行的。
chmod u + x /usr/local/bin/letsencrypt-renew.sh将作业添加到cron,以便自动更新证书。
@ mensual / usr / bin / certbot更新--renew-hook“ /usr/local/bin/letsencrypt-renew.sh”; /var/log/letsencrypt-renewal.logNginx的
使用sudo apt安装Certbot和Nginx插件后,请安装certbot python3-certbot-nginx,生成证书。
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp-通过电子邮件发送YOUR_EMAIL -d YOUR_DOMAIN如果要使用4096位密钥,则添加参数--rsa-key-size 4096。
从上方复制并粘贴整个Nginx示例配置文件,根据您的配置更改参数并取消注释。
将作业添加到cron,以便自动更新证书。
回显“ 0 0 * * * root certbot更新--quiet --no-self-upgrade --post-hook $0027systemctl reload nginx$0027” | sudo tee -a /etc/cron.d/renew_certbot