使用certbot自动申请免费证书

SSH进入服务器,以具有Sudo特权的用户运行您的HTTP网站。 安装系统依赖项

对于基于Debian的发行版(例如Debian,Ubuntu …):

$ sudo apt update
$ sudo apt install python3 python3-venv libaugeas0 

用于基于RPM的分布(例如Fedora,Centos …):

$ sudo dnf install python3 augeas-libs 

如果您使用OS软件包管理器安装了任何certbot软件包,apt,dnf, 或者 yum,在安装certbot快照之前,应删除它们,以确保运行命令时 certbot 使用该快照,而不是从操作系统的安装 软件包管理器。这样做的确切命令取决于您的操作系统,但是 常见的例子是sudo apt-get remove certbot,sudo dnf remove certbot, 或者 sudo yum remove certbot。 设置Python虚拟环境

在计算机上的命令行上执行以下说明以设置虚拟环境。

$ sudo python3 -m venv /opt/certbot/
$ sudo /opt/certbot/bin/pip install -upgrade pip 

安装certbot

在计算机上的命令行上运行此命令以安装CERTBOT。

$ sudo /opt/certbot/bin/pip install certbot certbot-nginx 

准备certbot命令

在计算机上的命令行上执行以下指令,以确保certbot命令可以运行。

$ sudo ln -s/opt/certbot/bin/certbot/usr/bin/certbot 

选择您想如何运行certbot

要么获得并安装您的证书…

运行此命令以获取证书并让Certbot自动编辑您的NGINX配置以使用它,并在一个步骤中打开HTTPS访问。

$ sudo certbot -nginx 

或者,只需获得证书

如果您感觉更保守,并且想手动对NGINX配置进行更改,请运行此命令。

$ sudo certbot certonly -nginx 

设置自动续订

我们建议运行以下行,这将为默认的crontab添加CRON作业。

$ 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

确认Certbot工作

要确认您的网站设置正确,请访问 https://yourwebsite.com/ 在您的浏览器中,在URL栏中查找锁定图标。

升级CERTBOT

$ sudo /opt/certbot/bin/pip install --upgrade certbot certbot-nginx

如果此步骤导致错误,请运行 sudo rm -rf /opt/certbot 并重复所有安装说明。

如果后期想要修改域名过期提醒的邮件地址,可以使用以下命令:

$ certbot update_account --email yourname@example.com

来源:https://certbot.eff.org/instructions?ws=nginx&os=pip

发表评论

zh_CNChinese