certbot #
可通过命令获取免费SSL证书。
Install certbot #
官方文档: https://certbot.eff.org/
Linux (snap) #
bash
# 通过snap安装certbot命令工具(需要事先安装 snapd,并卸载包管理器方式安装的 certbot):
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
Linux (pip) #
bash
# 安装 python3 环境(需要 python3.6+ 版本,并卸载包管理器方式安装的 certbot):
# On Ubuntu:
sudo apt install python3 python3-venv libaugeas0
# On Fedora:
sudo dnf install python3 augeas-libs
# On CentOS (old distributions, use python3X instead of python3):
sudo yum install python39
# 准备 pip 环境
sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip
# 安装 certbot
sudo /opt/certbot/bin/pip install certbot certbot-nginx
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot
Depoly certificate for nginx #
bash
# 查找nginx中的网站,交互式安装证书
sudo certbot --nginx
# 如果nginx安装在非标准目录,命令如下:
sudo certbot --nginx \
--nginx-ctl /usr/local/openresty/nginx/sbin/nginx \
--nginx-server-root /usr/local/openresty/nginx/conf
# 仅获取证书,不更改nginx配置文件
sudo certbot certonly --nginx
# 帮助
certbot --help
Renew certificate #
bash
# 编辑定期执行
sudo crontab -e
# 查看任务
sudo crontab -l
注意不同版本certbot命令存放位置不同,可能还需要将certbot命令所在目录添加到PATH中:
text
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
16 6 * * * certbot renew --quiet
#16 6 * * * certbot renew --quiet --force-renewal
旧版本 certbot 可能会出现的问题 #
旧版本 certbot 依赖 python2,可能会出现部分依赖包找不到的问题或版本问题。
text
问题:pkg_resources.DistributionNotFound: The 'certbot==0.22.0' distribution was not found and is required by the application
解决:pip install certbot==0.22.0
text
问题:AttributeError: 'module' object has no attribute 'SSL_ST_INIT'
解决:pip install pyOpenSSL==16.2.0
text
问题:raise ImportError("No module named '%s'" % (name,))
ImportError: No module named 'requests.packages.urllib3'
解决:pip install -U urllib3
text
问题:pkg_resources.ContextualVersionConflict:
(idna2.6(/usr/lib64/python3.4/site-packages),
Requirement.parse('idna<2.6,>=2.5'), {'requests'})
解决:pip install idna<2.6
text
问题:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 1: ordinal not in range(128)
原因:因为默认情况下,Python采用的是ascii编码方式
解决1:在/usr/lib/python2.7/site-packages/目录下添加一个sitecustomize.py文件,加入内容
import sys
sys.setdefaultencoding('utf-8')
解决2:nginx配置文件去掉中文字符