使用certbot提供https证书服务

问题:阿里云服务器(centos7)的1年免费域名证书到期了。

方案:lets-encrypt提供了新的客户端。官方文档:https://certbot.eff.org/lets-encrypt/centosrhel7-nginx

  1. 安装客户端

yum -y install yum-utils

yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

yum install python2-certbot-nginx

  1. 解决运行报错

运行certbot --nginx 报错:ImportError: No module named 'requests.packages.urllib3‘


pip install --upgrade pip

pip install --upgrade --force-reinstall 'requests==2.6.0' urllib3

  1. 生成证书

nginx -s stop // 先停止nginx服务,第一次没停服务,导致失败,没有live目录

certbot certonly --standalone -d "abc.com"  // 成功的话提示Congratulations, 按道理可以一次加多个域名,没成功,估计是哪块语法有问题

默认在/etc/letsencrypt下会生成live目录,下面有abc.com目录

  1. 修改nginx证书配置路径

ssl_certificate /etc/letsencrypt/live/abc.com/fullchain.pem;

ssl_certificate_key  /etc/letsencrypt/live/abc.com/privkey.pem;

  1. 重启nginx,ok
    6. 证书有效期3个月,可以设置自动更新
crontab -e
0 2 1 * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew 

异常:
1.chrome访问正常,safari 有问题,证书提示名称不一致
原因:domain.com 和 www.domain.com 用了一套证书,之前用阿里云申请的证书没问题,换了以后有问题。给www的重新生成证书就可以了

  1. 自动更新没起作用
    certbot renew命令报错,需要先停止nginx
  2. 收到邮件提醒,TLS-SNI-01 validation is reaching end-of-life
    按照提示升级certbot,https://community.letsencrypt.org/t/how-to-stop-using-tls-sni-01-with-certbot/83210
    renew后没起作用,用上面的脚本手动更新就可以了
    4.Another instance of Certbot is already running
    find / -type f -name ".certbot.lock" -exec rm {} ;

你可能感兴趣的:(使用certbot提供https证书服务)