如何在带有 nginx 的 Amazon Linux 2 上使用 certobot/letsencrypt 启用 HTTPS

Maj*_*ico 6 nginx amazon-ec2 lets-encrypt certbot amazon-linux-2

在 Amazon Linux 2 上安装 certbot/letsencrypt 并在 nginx 上启用 HTTPS(适用于 apache 的类似过程)

Maj*_*ico 27

安装证书机器人

sudo yum update
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum-config-manager --enable epel
sudo yum install certbot python3-certbot-nginx
certbot --version
Run Code Online (Sandbox Code Playgroud)

生成认证

使用以下命令生成证书并自动让 certbot 修改 nginx 配置以启用 https:

sudo certbot --nginx
Run Code Online (Sandbox Code Playgroud)

或者,如果您只需要认证,请使用以下命令:

sudo certbot certonly --nginx
Run Code Online (Sandbox Code Playgroud)

认证将在文件夹中创建

/etc/letsencrypt/live/ YOUR_SITE_NAME /

例如:

认证

/etc/letsencrypt/live/www.my-site.com/cert.pem

私钥

/etc/letsencrypt/live/www.my-site.com/privkey.pem


启用自动续订

使用以下命令启用认证自动续订:

sudo certbot renew --dry-run
Run Code Online (Sandbox Code Playgroud)

我遇到的错误

如果在创建认证的过程中出现如下错误:

“无法选择适当的插件:请求的 nginx 插件似乎未安装”

然后运行命令

sudo yum install certbot python-certbot-nginx
Run Code Online (Sandbox Code Playgroud)

并重试创建认证。

笔记

对于 apache,您可以使用python2-certbot-apacheinstad of python2-certbot-nginx,确保您使用该选项--apache而不是--nginx在创建认证期间使用该选项。

DNS 必须配置为指向您的计算机,否则 certbot 的检查将失败。

  • 这不适用于 Amazon Linux 2023。我在尝试安装 epel 时收到错误:错误:问题:请求冲突 - 没有提供 epel-release-7-14.noarch 所需的 redhat-release >= 7 (5认同)

arc*_*ryx 7

2023 年 7 月,Amazon Linux 2 不支持 epel 存储库。但是,如果您能够 ssh 进入计算机,则可以使用 python 包。

就像这样:

sudo pip3 install certbot certbot-nginx

# then execute
sudo /usr/local/bin/certbot --nginx -d ilovetoast.com www.ilovetoast.com
Run Code Online (Sandbox Code Playgroud)

参考: