Debian系统移步:

Nginx + CertBot 配置HTTPS泛域名证书(Debian)

# 安装nginx 
此步省略, 以nginx安装在'/usr/local/nginx-1.23.3'目录为例
# 1. 安装certbot
yum install certbot python2-certbot-nginx -y
# 2. 自动配置, --nginx-server-root指定nginx配置文件目录
certbot --nginx --nginx-server-root /usr/local/nginx-1.23.3/conf

# 3. 检测证书
certbot certificates
### certbot renew --dry-run

# 4. 证书自动续约
## 证书续约命令: /usr/bin/certbot renew

## 4.1 编辑定时任务
crontab -e
## 4.2 配置12小时执行一次
0 */12 * * * root test -x /usr/bin/certbot && /usr/bin/certbot renew --quiet

执行完后nginx.conf会自动加上SSL相关配置

常见问题

执行certbot --nginx --nginx-server-root /usr/local/nginx-1.23.3/conf命令报错:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
The nginx plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.",)

解决方案:

ln -s /usr/local/nginx-1.23.3/sbin/nginx /usr/bin/nginx
ln -s /usr/local/nginx-1.23.3/conf/ /etc/nginx

YYGP
25 声望11 粉丝

写BUG