【问题标题】:Lets-encrypt Error: Failed HTTP-01 Pre-Flight / Dry RunLets-encrypt 错误:HTTP-01 飞行前/试运行失败
【发布时间】:2020-01-10 19:21:21
【问题描述】:

我在README file examples 之后设置了一个基于redbird 的代理。

到目前为止,我已经为 http 和 https 配置了单个域,并且运行良好(https 仍然使用自签名证书)。

但现在我正在尝试将其配置为使用letsencrypt自动获取有效的ssl证书,但我陷入了以下错误:

 {"level":30,"time":1578681102208,"pid":21320,"hostname":"nigul","name":"redbird","0":false,"1":"setChallenge called for 'exposito.bitifet.net'","msg":"Lets encrypt debugger","v":1}
[acme-v2] handled(?) rejection as errback:
Error: Error: Failed HTTP-01 Pre-Flight / Dry Run.
curl 'http://exposito.bitifet.net/.well-known/acme-challenge/test-cf55199519d859042f695e620cca8dbb-0'
Expected: 'test-cf55199519d859042f695e620cca8dbb-0.MgLl7GIS59DPtPMejuUcXfddzNt8YxfLVo5op670u8M'
Got: '<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>404 - Not Found</title>
 </head>
 <body>
  <h1>404 - Not Found</h1>
 </body>
</html>
'
See https://git.coolaj86.com/coolaj86/acme-v2.js/issues/4
    at /home/joanmi/SERVICES/redbird_domains/node_modules/acme-v2/index.js:49:10
    at process._tickCallback (internal/process/next_tick.js:68:7)

据我了解,这告诉我 Lets Encrypt 正在尝试使用以下命令访问 url http://exposito.bitifet.net/.well-known/acme-challenge/test-cf55199519d859042f695e620cca8dbb-0

curl 'http://exposito.bitifet.net/.well-known/acme-challenge/test-cf55199519d859042f695e620cca8dbb-0'

...它似乎是一个 404 HTML 错误页面,我不知道它会出现在哪里。

事实上,执行那个 curl 命令或者只是在我的浏览器中粘贴 that url(你可以试试:我让服务器运行),我得到了给定的 Expected 字符串所以,从我的角度来看,如果我的配置是正确的,但由于某种原因,Lets Encrypt 的服务器正在访问另一台服务器(因为路由或 DNS 错误)。

但另一方面,我想更有可能是我在配置中做错了什么。

在这里我粘贴我的整个脚本(端口 80 和 443 分别通过 iptables 重定向到 1080 和 1443,因为该脚本是由非特权用户运行的):

const Redbird = require("redbird");

const proxy = Redbird({
    port: 1080,
    xfwd: false, // Disable the X-Forwarded-For header
    letsencrypt: {
    path: __dirname + '/certs',
    port: 9999
            // LetsEncrypt minimal web server port for handling challenges.
            // Routed 80->9999, no need to open 9999 in firewall. Default 3000
            // if not defined.
    },
    ssl: {
        http2: true,
        port: 1443, // SSL port used to serve registered https routes with LetsEncrypt certificate.
    }

});


proxy.register('exposito.bitifet.net:9999', 'http://localhost:8001', {
  ssl: {
    letsencrypt: {
      email: 'xxxxxx@gmail.com', // Domain owner/admin email
      production: false,
                // WARNING: Only use this flag when the proxy is verified to
                // work correctly to avoid being banned!
    }
  }
});

proxy.register("exposito.bitifet.net", "http://localhost:8001");

欢迎提供任何线索。

谢谢。

【问题讨论】:

    标签: lets-encrypt redbird


    【解决方案1】:

    已解决!!

    同时涉及许多问题(尽管我缺乏使用 redbird 和letsencrypt 的经验。

    1. magic 404/未找到页面:我猜它来自一个似乎已预装在我的 VPS 中的 lighttpd 服务器。

    端口 80 是通过 iptables 重定向的,但我想在一个或其他配置调整中,我可以将传入请求重定向到 localhost 的端口 80(未重定向)。

    1. 我对 redbird 的误解: 查看其 README 文件中的示例,我认为 redbird 有点“multi- reverse_proxy”,因为您可以使用单个 redbird 重定向 http 和 https 请求实例。

    但我终于意识到(可能不是那么好命名的)port 选项实际上是一个 http 端口,仅用于配置内置的无条件 http->https 重定向器(其中我已经阅读过,但我认为它是可选的)。

    1. 实际的潜在问题:如果您的 DNS 激活了 DNSSEC,您应该在其中定义一个 CAA 寄存器,指向 letsencrypt.org

    目前我禁用了 DNSSEC,因为我的提供商的控制面板不允许我创建此类注册。

    我在尝试通过 certbot (sudo apt-get install certbot 我必须说的是,如果我之前知道它,我不会在乎尝试 redbird 的letsencrypt 集成时发现它.

    它更加冗长(而当出现错误时,redbird 更像是一个黑盒子)并指出我需要 CAA 寄存器。

    这里是我做的笔记(以防有人感兴趣):

    Free SSL Certificates with Certbot
        Install certbot:
            sudo apt-get install certbot
        Create:
            sudo certbot certonly --manual --preferred-challenges http -d <domain>
        Renew:
            sudo certbot renew
        Caveats:
            DNSSEC
                If your DNS server has DNSSEC enabled, you will need to add a CAA
                register pointing to letsencrypt.org.
                ...and your DNS provider my not allow to create it (at least I
                couldn't with CDMON. Also not -yet- complained).
    
    1. production = false 用于其他类型的测试: 我读到如果你在测试时输入 true,如果你执行太多请求,你可能会被禁止使用letsencrypt。

    将其设置为 false 可以测试重定向,但是即使您可以在 没有 安全证书的情况下导航(我认为提供了某种自签名以允许测试),您仍然会看到有关 letencrypt 的错误。所以不要指望一个有效的。

    1. ssl 端口用于重定向: 不是(大)问题,但如果您指定 443 以外的 ssl 端口,内置重定向器将无条件地将您重定向到该端口。

    以 root 身份运行 redbird 并使用标准(80 和 443)端口可以正常工作。但是,如果您像我一样,想使用替代端口来使用非特权用户执行 redbird,您将被重定向到该替代端口而不是 443(即使它通过 iptables 重定向)。


    这是我(几乎*)最终的 redbird 脚本:

    const Redbird = require("redbird");
    
    const proxy = Redbird({
        port: 1080,
        xfwd: false, // Disable the X-Forwarded-For header
        ssl: {
            port: 1443,
        },
        letsencrypt: {
            path: __dirname + '/certs',
            port: 9999,
                    // LetsEncrypt minimal web server port for handling challenges.
                    // Routed 80->9999, no need to open 9999 in firewall. Default 3000
                    // if not defined.
        },
    
    });
    
    proxy.register('exposito.bitifet.net', 'http://exposito.bitifet.net:8001', {
        ssl: {
            http2: true,
            letsencrypt: {
              email: 'xxxxxx@gmail.com', // Domain owner/admin email
              production: true,
                        // WARNING: Only use this flag when the proxy is verified to
                        // work correctly to avoid being banned!
    
            },
        }
    });
    

    (*) 我仍然需要修复显式端口重定向问题 (5),因为我不想以 root 身份运行 redbird。但我知道可以允许用户监听给定的端口。甚至我可能最好尝试修补 redbird 以允许分别指定侦听和重定向端口。

    编辑: 它已经使用 ssl 部分中的(可选)选项 redirectPort 实现(并记录)。刚刚添加了redirectPort: 443 并完成了工作!!

    编辑 2:为了完成,我还有另一个问题。

    为了让事情顺利进行,我最终配置了重定向到 http 端口而不是 https 端口。

    即:传入的 https 请求被重定向到我的应用程序 http 端口。

    这看起来很奇怪,但它确实有效。至少如果您不需要任何专有的 https 功能,例如推送通知(我计划在未来使用)。

    但这意味着在本地主机上至少打开一个 http 服务器。现在这不是一个主要问题(这只是一个操场服务器),但我计划在工作中使用 redbird 将多个域代理到不同的服务器,这样会迫使我们至少在我们的 DMZ vlan 中打开 http(这是一个最好避免的额外风险...)。

    当我尝试重定向到 https 时,我收到了 DEPTH_ZERO_SELF_SIGNED_CERT 错误。

    好的:这告诉我 redbird(或节点)不信任我的原始(自签名)证书。我知道有一个选项可以告诉节点接受这些证书。但也许这不是要走的路……

    所以我将我的应用程序配置为使用 redbird 通过letsencrypt 获得的相同证书。

    但后来我得到了另一个错误:

    UNABLE_TO_VERIFY_LEAF_SIGNATURE
    

    研究了一下,我发现this StackOverflow answer 解释了如何获得Mozilla 信任的所有根证书和中间证书,并使节点信任它们。

    所以,最后,我所做的是:

    1. 已安装 node_extra_ca_certs_mozilla_bundle 包:

      npm install --save node_extra_ca_certs_mozilla_bundle
      
    2. package.jsonscripts 部分中的 start 命令前添加 NODE_EXTRA_CA_CERTS=node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem

    3. 更新了我的 redbird 脚本以再次指向 https(协议和)端口:

      proxy.register('exposito.bitifet.net', 'https://localhost:4301', {...]);
      

    这是我最终的 redbird 配置:

    const Redbird = require("redbird");
    
    const proxy = Redbird({
        port: 1080,
        xfwd: false, // Disable the X-Forwarded-For header
        ssl: {
            port: 1443,
            redirectPort: 443
            // key: "/etc/bitifet/exposito/ssl/private.key",
            // cert: "/etc/bitifet/exposito/ssl/public.cert",
        },
        letsencrypt: {
            path: __dirname + '/certs',
            port: 9999,
                    // LetsEncrypt minimal web server port for handling challenges.
                    // Routed 80->9999, no need to open 9999 in firewall. Default 3000
                    // if not defined.
        },
    
    });
    
    proxy.register('exposito.bitifet.net', 'https://localhost:4301', {
        ssl: {
            http2: true,
            letsencrypt: {
              email: 'xxxxxx@gmail.com', // Domain owner/admin email
              production: true,
                        // WARNING: Only use this flag when the proxy is verified to
                        // work correctly to avoid being banned!
    
            },
        }
    });
    

    这里是我的 package.json 文件内容:

    {
      "name": "redbird_domains",
      "version": "0.0.1",
      "description": "Local Domains Handling",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "start": "NODE_EXTRA_CA_CERTS=node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem node ./index.js"
      },
      "author": "Joanmi",
      "license": "GPL-3.0",
      "dependencies": {
        "node_extra_ca_certs_mozilla_bundle": "^1.0.4",
        "redbird": "^0.10.0"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-08
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-19
      • 2018-07-05
      相关资源
      最近更新 更多