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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM