跳转到内容

SSL

1 post with the tag “SSL”

让我们用 Certbot 加密

一、简介这篇文章将介绍如何使用 HTTPS 和 [Certbot][certbot] 来加密您的网站。

Section titled “一、简介这篇文章将介绍如何使用 HTTPS 和 [Certbot][certbot] 来加密您的网站。”

所有步骤基于CentOS/RHEL(Red Hat Enterprise Linux)。

2. 环境要求- 操作系统:CentOS/RHEL- 软件包:certbot(可选:certbot-dns-cloudflare)- 主机名:example.com

Section titled “2. 环境要求- 操作系统:CentOS/RHEL- 软件包:certbot(可选:certbot-dns-cloudflare)- 主机名:example.com”

3.安装Certbot使用 dnf 包管理器在您的系统上安装 certbot:

Section titled “3.安装Certbot使用 dnf 包管理器在您的系统上安装 certbot:”
sudo dnf install python3-certbot

如果您想使用 dns-01 挑战,我们以cloudflare为例,您应该安装certbot-dns-cloudflare插件:

sudo dnf install python3-certbot-dns-cloudflare

确保您已将主机名设置为主机 IP。

(2)。配置防火墙允许主机上的端口80:

Section titled “(2)。配置防火墙允许主机上的端口80:”
sudo firewall-cmd --add-port=80/tcp

(3)。使用 Certbot 颁发 SSL 证书使用以下命令从[Let’s Encrypt][letEnc]颁发SSL证书

Section titled “(3)。使用 Certbot 颁发 SSL 证书使用以下命令从[Let’s Encrypt][letEnc]颁发SSL证书”
sudo certbot certonly -d example.com

私钥和公钥将存储在文件夹/etc/letsencrypt/live/example.com/中。

(4)。使用 SSL 证书配置您的站点这不是本文的重点,配置应根据所使用的 Web 服务器而有所不同。请参阅在线其他资源。

Section titled “(4)。使用 SSL 证书配置您的站点这不是本文的重点,配置应根据所使用的 Web 服务器而有所不同。请参阅在线其他资源。”

可选-1。自动使用 Certbot 配置 Nginx如果您使用[Nginx][nginx],使用--nginx参数会很方便,替换*step(3)*中的命令:

Section titled “可选-1。自动使用 Certbot 配置 Nginx如果您使用[Nginx][nginx],使用--nginx参数会很方便,替换*step(3)*中的命令:”
sudo certbot certonly -d example.com --nginx

然后所有配置将在位于/etc/nginx/conf.d/example.com.conf的 nginx 文件中完成

可选-2。dns-01的问题dns_cloudflare插件通过使用 Cloudflare API 创建并随后删除 TXT 记录,自动完成dns-01挑战 (DNS01) 的过程。

Section titled “可选-2。dns-01的问题dns_cloudflare插件通过使用 Cloudflare API 创建并随后删除 TXT 记录,自动完成dns-01挑战 (DNS01) 的过程。”

以下命令将执行此操作:

sudo certbot certonly \
--dns-cloudflare \
--dns-cloudflare-credentials ~/PATH_TO_CF_KEY/cf_key.txt \

在本节中,cf_key.txt包含来自 Cloudflare 的 [API TOKEN][API] 或 [Global API Key][APIKEY],以下是这两个结构的示例:

# Cloudflare API token used by Certbot
dns_cloudflare_api_token = 0123456789abcdef0123456789abcdef01234567
# Cloudflare API credentials used by Certbot
dns_cloudflare_email = cloudflare@example.com
dns_cloudflare_api_token = 0123456789abcdef0123456789abcdef01234

[2].https://developers.cloudflare.com/fundamentals/api/get-started/create-token/ [3].https://developers.cloudflare.com/fundamentals/api/get-started/keys/ [certbot]:https://certbot.eff.org [letEnc]:https://letsencrypt.org/ [nginx]:https://www.nginx.com [API]:https://developers.cloudflare.com/fundamentals/api/get-started/create-token/ [APIKEY]:https://developers.cloudflare.com/fundamentals/api/get-started/keys/ [4]. 使用 RHEL 上的 Nginx 进行反向代理