使用Certbot签发Https证书之Nginx
最近业务需要为API接口域名配置HTTPS证书 决定使用方便的certbot进行Let’s Encrypt免费证书签发部署
环境:
CentOS 7
Nginx 1.13
签发证书
- 下载certbot-auto脚本 1 wget https://dl.eff.org/certbot-auto 
- 提权并开始签发证书1 
 2
 3chmod +x /usr/local/bin/certbot-auto 
 // 使用standalone方式签发证书
 ./usr/local/bin/certbot-auto certonly --standalone --email xxxx@gmail.com -d example.com
- 建议将certbot-auto脚本移至/usr/local/bin下
 在登录用户下运行会报出如下错误 
- -d 指定域名有几种方式 - 指定单域名 后接域名即可
- 指定多域名 -d xx.xx -d xx1.xx -d xx2.xx
- 泛域名 -d *.xx.xx
 
- 签发前需确保nginx命令执行正常 
- 在签发前需要将nginx停止 否则会报80端口已占用 
之后会有几步提示 根据具体环境选择:
- 是否重新签发证书并替换现有证书 – no
- 是否将http请求全部重定向至https  – yes
 一切顺利 证书成功下发 ! 
重签测试
测试前需要停止nginx
| 1 | ./usr/local/bin/certbot-auto renew --dry-run | 
很顺利
 
  
测试后需要重启nginx :(
自动重签
使用crontab定时重签证书
| 1 | 0 3 */10 * * /usr/local/bin/certbot-auto renew --disable-hook-validation --renew-hook "/usr/local/nginx/nginx -s re | 
END