【问题标题】:Let's Encrypt unauthorized 403 forbidden让我们加密未经授权的 403 禁止
【发布时间】:2017-08-13 11:49:02
【问题描述】:

在服务器上,安装了 Nginx。 Let's Encrypt 适用于 www.domain.com,但不适用于 static.domain.com

使用 PuTTY,当我输入时: sudo letsencrypt certonly -a webroot --webroot-path=/var/www/site/domain -d static.domain.com -d domain.com -d www.domain.com

我有以下问题:

Failed authorization procedure. static.domain.com (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://static.domain.com/.well-known/acme-challenge/c6zngeBwPq42KLXT2ovW-bVPOQ0OHuJ7Fw_FbfL8XfY: "<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>"

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

   Domain: static.domain.com
   Type:   unauthorized
   Detail: Invalid response from
   http://static.domain.com/.well-known/acme-challenge/c6zngeBwPq42KLXT2ovW-bVPOQ0OHuJ7Fw_FbfL8XfY:
   "<html>
   <head><title>403 Forbidden</title></head>
   <body bgcolor="white">
   <center><h1>403 Forbidden</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.

有人知道可能是什么问题吗?

【问题讨论】:

    标签: nginx encryption lets-encrypt unauthorized


    【解决方案1】:

    当我第一次尝试在我的网站上安装证书时,我从 certbot 收到了相同的错误消息。

    在网络服务器上检查原因

    我使用的是 apache2,而不是 nginx。我查看了/var/log/apache2/error.log 中的日志以查找与我网站上的 403 Forbidden 事件相关的 apache2 错误消息,我发现:

    [Sun Aug 26 14:16:24.239964 2018] [core:error] [pid 12345] (13)Permission denied: [client 12.34.56.78:1234] AH00035: access to /.well-known/acme-challenge/5PShRrf3tR3wmaDw1LOKXhDOt9QwyX3EVZ13JklRJHs denied (filesystem path '/var/lib/letsencrypt/http_challenges') because search permissions are missing on a component of the path
    

    权限和访问问题

    我google了这个错误信息,发现apache2无法读取上面提到的目录(例如/var/lib/letsencrypt/http_challenges),因为权限不正确,例如:

    $ sudo ls -la /var/lib/letsencrypt/
    total 16
    drwxr-x---  4 root root 4096 Aug 26 14:31 .
    drwxr-xr-x 72 root root 4096 Aug 18 00:48 ..
    drwxr-x--- 27 root root 4096 Aug 26 14:26 backups
    drwxr-xr-x  2 root root 4096 Aug 26 14:27 http_challenges
    

    因此,根据上面带有点(.)的行,代表letsencrypt具有权限rwxr-x---的文件夹,除了root用户之外没有人可以读取其内容。为了纠正权限,我刚刚做了:

    解决方案

    $ sudo chmod o+rx /var/lib/letsencrypt
    

    将上述$ ls 命令输出更改为:

    $ ls -la /var/lib/letsencrypt/
    total 16
    drwxr-xr-x  4 root root 4096 Aug 26 14:31 .
    drwxr-xr-x 72 root root 4096 Aug 18 00:48 ..
    drwxr-x--- 27 root root 4096 Aug 26 14:26 backups
    drwxr-xr-x  2 root root 4096 Aug 26 14:27 http_challenges
    

    现在,上面带有点 (.) 的行表示letsencrypt 目录表示rwxr-xr-x,因此“其他用户”(如用户www-data对于 apache2) 现在可以读取并通过 letsencrypt 目录。

    然后 certbot 按预期工作。

    【讨论】:

      【解决方案2】:

      在您的服务器块中,添加:

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

      【讨论】:

      • 我稍微改了一下,为什么这个就不行了?
      【解决方案3】:

      我猜你的子域有另一个 webroot,如果有,只需要指定那个 webroot。在您的示例中,both static.domain.comdomain.com 具有相同的 webroot。

      来自https://certbot.eff.org/docs/using.html

      如果您同时获得多个域的证书,该插件 需要知道每个域的文件是从哪里提供的,这可以 可能是每个域的单独目录。当请求一个 多个域的证书,每个域将使用最多 最近指定的 --webroot-path

      certbot certonly --webroot -w /var/www/example/ -d www.example.com -d example.com -w /var/www/other -d other.example.net -d another.other.example.net

      【讨论】:

      • 非常感谢克里斯!我做了你告诉我的事情:sudo certbot certonly --webroot -w /var/www/site/domain/ -d domain.com -d www.domain.com -w /var/www/site/domain/wp-content/uploads/ -d static.domain.com 但我有同样的问题 403 Forbidden
      • 我看到很多线程有类似的错误,似乎有很多可能的问题。域的 webroot 中是否有 .htaccess 文件?
      • 不,该域的 webroot 中没有 .htaccess 文件。
      • 我遇到了同样的问题,检查了这个链接.well-known ACME challenge files blocked 403 Forbidden in some Nginx configurations,这表明问题存在于 nginx.conf 文件中?我试图编辑它,但它是只读的。你找到解决办法了吗?
      • @PauloHenrique 您可能不再需要它了,但是感谢您的链接,我找到了一个适合我的答案。我在这里添加它作为答案。
      【解决方案4】:

      我遇到了一种解决方法,因为它不是解决方案(不是自动的),但它确实有效。

      您可以通过 Certbot 使用 DNS 质询证明您的域所有权;

      sudo certbot -d domain.com --manual --preferred-challenges dns certonly
      

      【讨论】:

        【解决方案5】:

        我不得不删除我的域的 AAAA 记录,因为 certbot 更喜欢 IPV6。我的虚拟主机提供商 DNS 有 www 和 @(域的根)的默认 AAAA 记录。

        在仔细检查 /var/log/letsencrypt/letsencrypt.log 之后,我发现它使用的是 IPV6 地址。就我而言,我在 www 上没有任何网站。或由 IPV6 地址提供服务的域的根目录,因此我删除了 AAAA 记录并立即解决了我的问题。由于 dns 传播和记录 ttl,其他人可能需要更长的时间才能看到缓解。

        certbot 将尝试使用 IPV6 地址连接到您,如果它能够解决一个问题,即使您期望通过 IPV4 进行连接,这就是我的问题的严重程度。

        我建议删除日志,以便在继续执行命令之前只有新条目 - sudo rm /var/log/letsencrypt/legsencrypt.log - 找到“addressUsed”并验证它是 IPV4 地址而不是 IPV6 地址.如果它是 IPV6 地址,请将该地址在网关处转发到您的主机并验证您是否也在侦听 IPV6,或者删除 DNS 中的 AAAA 记录,以便让 letencrypt 使用 IPV4 地址连接到您。

        【讨论】:

          【解决方案6】:

          如果有人仍然面临这个问题,可以在下面尝试,它对我有用:

          location ^~ /.well-known/acme-challenge/ {
          default_type "text/plain";
          alias /home/nginx/domains/domain.com/public/acme-challenge/;
          }
          

          【讨论】:

            【解决方案7】:

            就我而言,我拒绝通过

            访问安全相关文件(/.htaccess/.htpasswd 等)
            location ~ /\. {
              deny all;
            }
            

            我改成了

            location ~ /\.ht {
              deny all;
            }
            

            【讨论】:

              【解决方案8】:

              我不想不必要地重复,但似乎有一些不同的情况会导致证书更新时出现 403。对我来说,由于 Wordpress / url 重写,它与 更改的 nginx 配置 有关。顺便说一句,使用 Virtualmin

              上面的 cmets 中有一个链接指向 Github 上的一个问题。 One guy explains brilliantly how the location matches in nginx work and gives a solution for the 403。不过,也可能存在其他问题。

              因此,对我来说,解决方案是为 /.well-known/ 添加位置匹配。

              location ^~ /.well-known/ {
                  #limit_req            [tighter per-ip settings here]; ## kicked this one out
                  access_log           off;
                  log_not_found        off;
                  #root                 /var/www/html; ## kicked this one out
                  autoindex            off;
                  index                index.html; # "no-such-file.txt",if expected protos don't need it
                  try_files            $uri $uri/ =404;
              }
              

              我根本不是 nginx 专家,所以我鼓励你阅读这篇文章并检查你的情况需要哪些参数。

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2017-10-20
                • 2017-12-15
                • 2015-10-04
                • 2020-04-20
                • 1970-01-01
                • 1970-01-01
                • 2018-06-15
                • 2020-02-21
                相关资源
                最近更新 更多