目录

Nginx-Certbot配置-HTTPS-SSL-证书简化版已测试

目录

Nginx + Certbot配置 HTTPS / SSL 证书(简化版已测试)

前提条件:
1.已有域名
2.Nginx 已安装并正在运行,且有对应的 Server 配置,在nginx.conf 中配置好80(http)
3.防火墙开放 80 和 443 端口

#安装certbot
yum install certbot -y

#安装python-certbot-nginx
yum install python-certbot-nginx -y

#签发证书,替换你的域名yourdomain
certbot --nginx -d yourdomain

#检查 Certbot 版本
certbot --version	

重启nginx:

systemctl restart nginx

测试 Certbot 自动续期:

certbot renew --dry-run

真实续订(正式用):

certbot renew

该命令会检查所有即将过期的证书,并尝试续订。注意:在使用完签发命令后,需重新nginx使站点ssl配置生效。

自动续订(计划任务用):

#该命令可以将续订命令添加到crontab计划任务中,以实现自动续订,并重启nginx。
certbot renew --quiet --renew-hook 'sudo systemctl reload nginx'

#假设crontab计划任务会在每月1号执行1次续订命令,并在续订后重载Nginx配置,具体示例如下。
0 0 1 * * certbot renew --quiet --renew-hook 'sudo systemctl reload nginx' > /dev/null 2>&1