使用 Let‘s Encrypt(通过Certbot工具)自动续期ssl证书
2026年3月6日·16 次阅读·
提升
- 连接服务器:通过SSH登录到你的网站服务器。
- 安装Certbot:根据你的操作系统执行命令。
Ubuntu/Debian:
sudo apt update
sudo apt install certbot python3-certbot-nginx # 如果使用Nginx
# 或 sudo apt install certbot python3-certbot-apache # 如果使用Apache
CentOS/RHEL:
sudo yum install epel-release
sudo yum install certbot python3-certbot-nginx
- 关闭nginx
sudo systemctl stop nginx
- 申请并自动配置证书:
sudo certbot --nginx -d 你的域名.com -d www.你的域名.com
- 启动nginx
sudo systemctl start nginx
- 修改ssl证书路径
server {
listen 443 ssl http2;
server_name xxx.top www.xxx.top;
ssl_certificate /etc/letsencrypt/live/xxx.top/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xxx.top/privkey.pem;
# 其他原有配置...
}
- 重启nginx
# 测试配置文件语法是否正确
sudo nginx -t
# 如果上一步显示“syntax is ok”和“test is successful”,则重载Nginx使配置生效
sudo systemctl reload nginx
# 或
sudo nginx -s reload