Nginx获取Let’s Encrypt SSL证书

mac2025-04-19  0

Nginx获取Let’s Encrypt SSL证书

首先需要注册域名,然后把域名解析到你服务器的ip地址上。 1、下载Let’ s Encrypt客户端 Let’ s Encrypt客户端地址:https://github.com/certbot/certbot/releases

#下载Let’ s Encrypt客户端 curl -o certbot-0.39.0.tar.gz https://codeload.github.com/certbot/certbot/tar.gz/v0.39.0 #解压、进入目录 tar -zxvf certbot-0.39.0.tar.gz cd certbot-0.39.0 #检查升级 ./certbot-auto --help

此时会显示帮助文档。 2、获取证书: 方法一:停止nginx让出80端口,验证域名。

#停止nginx、查看运行状态 systemctl stop nginx systemctl status nginx #运行获取证书命令 ./certbot-auto certonly --standalone --email xxxx@xx.com -d www.xxxx.com

方法二:通过临时目录验证获取(不需要停止nginx让出80端口)

./certbot-auto certonly --webroot --email xxxx@xx.com -w /usr/share/nginx/html -d xxx.xxxx.com

执行成功则显示如下页面

获取证书成功后会保存在“/etc/letsencrypt/live/你申请的域名/” 目录下

域名自动续期脚本 新建/root/certbot-0.39.0/certbotrenew.sh文件写入以下内容

[root~]# vi /root/certbot-0.39.0/certbotrenew.sh #!/bin/sh #停止 nginx 服务,使用 --standalone 独立服务器验证需要停止当前 web server. systemctl stop nginx if ! /path/to/certbot-auto renew -nvv --standalone > /var/log/letsencrypt/renew.log 2>&1 ; then echo Automated renewal failed: cat /var/log/letsencrypt/renew.log exit 1 fi #启动 nginx systemctl start nginx

自动运行脚本

[root~]# chmod +x /root/certbot-0.39.0/certbotrenew.sh [root~]# crontab -e //写入以下内容 0 23 28 * * /bin/sh /root/certbot-0.39.0/certbotrenew.sh
最新回复(0)