certbot https签发证书与自动更新——acme实在太难用,certbot一键式全搞定

环境:centos 7.3

前言:acme.sh太折磨人了。通过nginx验证每次都等半天、能不能成碰运气,可能我姿势不对。手动倒是挺快,需要在域名解析中加一条txt记录,麻烦又不能自动更新。

按官网说明https://certbot.eff.org/lets-encrypt/centosrhel7-nginx
安装
yum install epel-release

yum -y install yum-utils
yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

sudo yum install certbot python2-certbot-nginx

1、如找不到urllib3(ImportError: No module named 'requests.packages.urllib3'),卸载然后重新安装
pip uninstall urllib3
pip uninstall requests
pip uninstall chardet

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

2、Certbot默认使用nginx的路径,如果是编译安装的、需要如下配置

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

使用:配置好nginx的server_name后签发证书,不用配置80端口,全自动;第一次需要输入邮箱、同意条款等
sudo certbot certonly --nginx

*如果报UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 2: ordi。。。blabla

说明配置文件中有非常规的字符,我不能确定是否与中文有关,因为成功的时候配置里面也有中文注释,再到第n次时却失败了。但是可以确定与包含.或者-的路径无关。

把配置文件打扫一下,先获取证书,发现可以成功。之后再把原本的配置文件替换回去就好了。

20200305更新:问题症结在于python环境编码

原文地址:https://my.oschina.net/u/571166/blog/88097

报错:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 0: ordinal not in range(128)

终于找到解决方法了:

在python的Lib/site-packages 文件夹下新建sitecustomize.py 

内容:

#encoding=utf8
import sys

reload(sys)
sys.setdefaultencoding('utf-8')

 ”

nginx ssl配置 替换yourdomain

ssl_certificate /etc/letsencrypt/live/yourdomain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/yourdomain/chain.pem;

手动更新

先测试一下

certbot renew --dry-run

成功再
certbot renew

定时任务自动更新
echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew" | sudo tee -a /etc/crontab > /dev/null

原文地址:https://www.cnblogs.com/feixuefubing/p/11947303.html