使用CertBot自动更新Nginx的ssl证书
1.安装snapd
1.1.添加EPEL
在CentOS 7系统中添加EPEL仓库
sudo yum install epel-release
1.2.安装snapd
使用仓库,安装snapd包
sudo yum install snapd
安装完成后,启动管理主要snapd通信套接字的systemd单元
sudo systemctl enable --now snapd.socket
创建软链接
sudo ln -s /var/lib/snapd/snap /snap
2.删除已存在的certbot
sudo apt-get remove certbot sudo dnf remove certbot sudo yum remove certbot
3.安装certbot
sudo snap install --classic certbot
3.1.创建软链接
sudo ln -s /snap/bin/certbot /usr/bin/certbot
3.2.运行CertBot
3.2.1.获取并安装证书
sudo certbot --nginx
3.2.2.只获取证书
sudo certbot certonly --nginx
4.测试自动更新
CertBot自带定时器,可以在证书过期钱自动更新证书,不需要再次运行CertBot,除非更改过配置。
以下命令可以测试证书的自动续订:
sudo certbot renew --dry-run
Congratulations, all simulated renewals succeeded:
/etc/letsencrypt/live/createverse.fun/fullchain.pem (success)
常见问题
1.提示 nginx.conf 文件找不到
nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory) nginx: configuration file /etc/nginx/nginx.conf test failed
解决方法:
使用自定义路径
sudo certbot --nginx --nginx-server-root=/usr/local/nginx/conf
懵懵懂懂迷迷糊糊