对具有分布式流量的多个 Apache 服务器使用 Lets Encrypt SSL

对具有分布式流量的多个 Apache 服务器使用 Lets Encrypt SSL

我在为两个不同服务器上设置的几个网站设置 Let's Encrypt 时遇到了一些问题,并且通过 HAProxy 将流量分发给它们。

这些服务器上有许多 VHost/域,它们都需要 SSL 证书。为了便于理解,我们假设它们如下:

  1. foo.some-site.com
  2. bar.some-site.com

这两个 A 记录都设置了两个 IP 地址。我可以使用 nwtools.com 或 nslookup 验证这两个 A 记录foo.some-site.combar.some-site.com解析相同的两个 IP 地址。我知道 Let's Encrypt 要求 vhost 具有有效的使用记录,以便进行查找。

我计划在两台服务器上为所有虚拟主机运行 Lets Encrypt 设置,其中一台服务器运行正常,但当我转到第二台服务器时,出现错误:

[root@server httpd]# /opt/letsencrypt/letsencrypt-auto --apache -d foo.some-site.com
Checking for new version...
Requesting root privileges to run letsencrypt...
   /root/.local/share/letsencrypt/bin/letsencrypt --apache -d foo.some-site.com
Failed authorization procedure. foo.some-site.com (tls-sni-01): urn:acme:error:connection :: The server could not connect to the client to verify the domain :: Failed to connect to host for DVSNI challenge

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: foo.some-site.com
   Type:   connection
   Detail: Failed to connect to host for DVSNI challenge

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A record(s) for that domain
   contain(s) the right IP address. Additionally, please check that
   your computer has a publicly routable IP address and that no
   firewalls are preventing the server from communicating with the
   client. If you're using the webroot plugin, you should also verify
   that you are serving files from the webroot path you provided.

这可能是因为它正在进行查找或尝试卷曲foo.some-site.com,并且可能会被定向到另一台服务器?我不确定这有什么关系,因为两者都有相同的 VHost,除非 LetsEncrypt 实际上正在监听它自己建立的连接……

让我感到困惑的是,它对其中一个人来说效果很好(比如说bar.some-site.com),那么为什么它对一个站点有效,但对另一个具有完全相同设置的网站却失败呢?

如果有人知道如何在两个不同的服务器上为相同的虚拟主机设置 Lets Encrypt,我将非常感激您的帮助!

答案1

这可能是因为它正在进行查找或尝试卷曲 foo.some-site.com,并且它可能被定向到另一台服务器?

是的,绝对是。

作为域验证质询-响应过程的一部分,LE 需要重新连接到运行 LE 客户端的服务器。无需赘述,LE 客户端实际上会暂时在您的 Web 服务器中提供某个文件,LE 服务器需要能够使用该文件来验证域所有权。

在所有后端服务器上运行此命令是不必要的,而且很麻烦。运行一次,然后将密钥和证书链复制到其余的后端服务器。

让我感到困惑的是,它在其中一个网站上运行良好(比如 bar.some-site.com),那么为什么它在一个网站上有效,而在另一个具有完全相同设置的网站上运行失败呢?

因为你很幸运?:) 有可能你的负载均衡器偶然将 LE 请求定向到正确的位置一次,但第二次却没有这样做。

答案2

涉及多个 Web/应用服务器/负载均衡器的场景有多种方法。您可以在官方 Let's Encrypt 集成指南适用于更大的环境。

有一些巧妙的方法可以做到这一点,例如:

  • 将所有验证请求重定向到单个验证主机/主机池
  • 离线执行所有证书管理(即从管理主机而不是在 Web 服务器上请求、更新和分发密钥)

对您来说有意义的事情取决于您的偏好和各种特定环境的要求。

相关内容