ubuntu上为nginx设置ssl证书

Let’s Encrypt提供了免费的证书,而且非常简单

参考Certbot Instructions | Certbot (eff.org)即可。这里记录一下操作过程,跟文档是一样的。

  1. 安装,apt python3 python3-venv libaugeas0
  2. 移除certbot,以防万一的操作。apt remove certbot
  3. 创建虚拟环境,我对python不熟悉,照敲而已,python3 -m venv /opt/certbot/
  4. 安装certbot和certbot-nginx,/opt/certbot/bin/pip install certbot certbot-nginx
  5. 创建软连接,ln -s /opt/certbot/bin/certbot /usr/bin/certbot
  6. 设置证书,certbot –nginx

不得不说这玩意真高级!

网上查了说证书有效期是90天,所以还是得把文档中最后的自动续期的定时任务加上

echo "0 0,12 * * * root /opt/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && sudo certbot renew -q" | sudo tee -a /etc/crontab > /dev/null

在用pip安装certbot和certbot-nginx时遇到了网络问题,懂的人都懂,可以设置一下使用阿里云的源,操作方法就是在~/.pip/pip.conf中添加如下设置:

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

不得不赞一下阿里云,大气!


评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注