使用Let’s Encrypt来启用HTTPS

简述

使用Let’s Encrypt设置证书时,我想着无论是第几次都可以。Ubuntu 20.04

安装管理工具

请运行以下命令以在您的系统上安装Certbot:
sudo apt -y 安装certbot

安装证书

将域名设置为您自己的。
使用sudo certbot –nginx -d mattermost.example.com命令。

如果收到以下消息,请选择“2”选项。
(不允许HTTP访问,重定向到HTTPS)

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

确认

在/etc/nginx/sites-available/default文件中,有一个注释”managed by Certbot”,并添加了一些配置。

请确认设置中是否有错误。

sudo nginx -t 的中文翻译可为:
使用sudo验证nginx配置是否正确。

只要以下内容可以确定无误即可。

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

为了反映设置更改,重新启动nginx。

请重新启动 Nginx 服务。

更新测试

由于使用测试服务器,所以偶尔会失败。
实际上第一次失败了,但第二次没问题…
sudo certbot renew –dry-run

如果成功的話

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/mattermost.example.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator nginx, Installer nginx
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for mattermost.example.com
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of nginx server; fullchain is
/etc/letsencrypt/live/mattermost.example.com/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

如果发生失败,请查看日志。
sudo less /var/log/letsencrypt/letsencrypt.log

2023-12-06 22:51:52,091:DEBUG:urllib3.connectionpool:https://acme-staging-v02.api.letsencrypt.org:443 "POST /acme/new-order HTTP/1.1" 201 355
2023-12-06 22:51:52,092:DEBUG:acme.client:Received response:
HTTP 201
(snip)
2023-12-06 22:51:52,228:DEBUG:urllib3.connectionpool:https://acme-staging-v02.api.letsencrypt.org:443 "POST /acme/authz-v3/********** HTTP/1.1" 404 106
2023-12-06 22:51:52,229:DEBUG:acme.client:Received response:
HTTP 404

在认证部分遇到了404错误。
然而,当我重新执行时,成功了,所以如果失败的话就应该冷静一下然后再次执行。

请确认更新时间表。

请原生汉语重新表达以下内容,只需提供一种选项:
sudo systemctl status certbot.timer

请使用以下命令查看Certbot计时器的状态:
sudo systemctl status certbot.timer

● certbot.timer - Run certbot twice daily
     Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled)
     Active: active (waiting) since Mon 2022-11-14 00:09:43 JST; 1 years 0 months ago
    Trigger: Thu 2023-12-07 15:03:49 JST; 3h 40min left
   Triggers: ● certbot.service

暫時只需要觀察一下,目前看起來應該沒問題。

请参考

让我们使用 Let’s Encrypt

【Ubuntu+Nginx】通过 Let’s Encrypt 发行 SSL 证书并进行 https 通信

使用 Certbot 定时器更新 Mattermost 的 SSL 证书