【问题标题】:Using certbot to apply Let's Encrypt Certificate: Failed authorization procedure使用 certbot 申请 Let's Encrypt 证书:授权程序失败
【发布时间】:2017-07-05 06:40:54
【问题描述】:

我正在使用certbot申请Let's Encrypt证书, 我的服务器是 centos 7.2 和 nginx 1.11.9。 下面是什么意思?

[root@test ~]# certbot certonly --webroot -w /var/www/www.example.com -d example.com -d www.example.com

Failed authorization procedure. example.com (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://example.com/.well-known/acme-ch
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>", www.example.com (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://www.example.com/.well-known/acme-challenge/k
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>"

IMPORTANT NOTES:
 - If you lose your account credentials, you can recover through
   e-mails sent to example@example.com.
 - The following errors were reported by the server:

   Domain: example.com
   Type:   unauthorized
   Detail: Invalid response from
   http://example.com/.well-known/acme-challenge/wGNv57IGJjHQ9wyzzALktpNaPzfnTtN3m7u3QuO4p40:
   "<html>
   <head><title>404 Not Found</title></head>
   <body bgcolor="white">
   <center><h1>404 Not Found</h1></center>
   <hr><center>"

   Domain: www.example.com
   Type:   unauthorized
   Detail: Invalid response from
   http://www.example.com/.well-known/acme-challenge/kFJ0CSuKOdgcT2xmciB4GGNCcnUPoIbpQmA9jOII_Bk:
   "<html>
   <head><title>404 Not Found</title></head>
   <body bgcolor="white">
   <center><h1>404 Not Found</h1></center>
   <hr><center>"

   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.
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.

我可以访问example.comwww.example.com,文档中有注释:https://certbot.eff.org/#centosrhel7-nginx

注意: 要使用 webroot 插件,您的服务器必须配置为从隐藏目录提供文件。如果 /.well-known 被您的网络服务器配置特殊处理,您可能需要修改配置以确保 /.well-known/acme-challenge 中的文件由网络服务器提供服务。

是这个原因吗? 如何修改配置?

【问题讨论】:

    标签: nginx https lets-encrypt


    【解决方案1】:

    这是一个很常见的问题,但幸运的是应该很容易解决。 Let's Encrypt 必须能够从 .well-known 目录中读取数据,以验证您的服务器确实托管了您想要证书的域。

    首先,确保您的网站根目录中有一个 .well-known 目录。设置您的权限,使其可以从外部读取; 775应该是完美的。

    然后,将这个 sn-p 添加到 Nginx 中的虚拟主机文件中:

        location ~ /.well-known {
                allow all;
        }
    

    这将允许对我们刚刚创建的 .well-known 目录的任何请求。现在,再次尝试申请证书,看看是否有效。

    【讨论】:

    • Certbot 自行创建和处理.well-known 目录,无需手动创建。
    • 另外,对于.well-known,重要的是要确保 nginx 不会阻止某个 conf 文件中的所有“点”文件,因为这会阻止 http-01 质询响应
    【解决方案2】:

    我遇到了这个问题。经过 4 个小时的艰苦调试,我发现了这一点。如果您的服务器同时支持 ipv4 和 ipv6,请确保您的服务器配置中有这两行:

    listen 80;
    listen [::]:80;
    

    第二行的 [::]: 告诉它监听 ipv6。如果您遗漏了第二行,那么当您运行 certbot 时,LetsEncrypt 服务器将尝试通过 ipv6 访问您的服务器。但是由于您的应用程序 vhost 没有在 ipv6 上侦听,如果您启用了它,nginx 会将其定向到 default vhost 处理程序(因为该处理程序确实在 ipv6 上侦听)。由于default 处理程序无法提供所需的质询文件,它会给出 404。


    如果这不能解决您的问题:通常,在调试 certbot 时,请确保该请求未被 default vhost(或任何其他 vhost)处理。您可以通过adding a log directive 对默认虚拟主机的配置文件进行检查,运行 certbot,然后检查您指定的日志文件以查看来自 Letsencrypt 的请求是否显示在其中。如果这不是问题,请检查您是否可以从浏览器访问质询文件。为此,您需要将 certbot 添加到应用程序配置文件的位置指令添加。 Certbot 会将其修改转储到其日志文件中的配置文件中。以我的经验,它实际上并没有在/.well-known/acme-challenge 中创建挑战文件。它实际上只是将该 url 的响应硬编码到配置文件中。所以重新创建它,然后检查您是否可以从浏览器访问它。

    【讨论】:

      【解决方案3】:

      @user234683 的回答对我帮助很大。

      就我而言,问题出在 cloudflare 上。不知何故,cloudflare 没有将 certbots 请求重定向到我的服务器。当我在浏览器上打开 /.well-known/acme-challenge 时,它清楚地提到了一个 cloudflare 错误。 所以在这里我做了什么,我在 cloudflare 上禁用了 ssl,然后在我的服务器上更新了证书 - 一切都在两分钟内完成。

      希望它对那里的人有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-25
        • 2019-03-20
        • 1970-01-01
        • 1970-01-01
        • 2021-12-22
        • 2016-11-15
        • 2021-06-20
        • 2020-04-25
        相关资源
        最近更新 更多