CentOS 上 Nginx 的 SSL 证书续期指南
一 准备与检查
sudo nginx -tsudo nginx -T(便于确认 server 配置与根路径)sudo yum install -y epel-releasesudo yum install -y certbot python2-certbot-nginxsudo certbot plugins(应能看到 nginx 插件)二 自动续期方式
sudo systemctl status certbot.timersudo systemctl enable --now certbot.timersudo crontab -e0 2 * * * /usr/bin/certbot renew --quiet --post-hook "systemctl reload nginx"sudo crontab -l 查看。三 测试与验证
sudo certbot renew --dry-run,看到 “The dry run was successful” 表示续期流程正常。sudo certbot renew --force-renewal(生产环境不建议频繁使用)。sudo nginx -t && sudo systemctl reload nginx。sudo certbot certificates。四 特殊场景与常见问题
sudo certbot --nginx --expand -d 已有域名 -d 新域名sudo certbot certonly --manual --preferred-challenges dns -d 你的域名location ^~ /.well-known/acme-challenge/ { root /var/www/html; }ssl_certificate /etc/letsencrypt/live/你的域名/fullchain.pem;ssl_certificate_key /etc/letsencrypt/live/你的域名/privkey.pem;sudo systemctl reload nginx。