Let's Encrypt 禁止未经授权的 403

问题描述 投票:0回答:9

服务器上安装了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
9个回答
11
投票

当我第一次尝试在我的网站上安装证书时,我从 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
,因此“其他 用户”(如 apache2 的用户 www-data)现在可以读取并浏览
letsencrypt
目录。

然后 certbot 按预期工作。


3
投票

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

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

3
投票

我必须删除我的域的 AAAA 记录,因为 certbot 更喜欢 IPV6。我的网络主机提供商 DNS 具有 www 和 @(域根)的默认 AAAA 记录。

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

certbot 会尝试使用 IPV6 地址连接到您(如果它能够解析),即使您期望通过 IPV4 连接,这就是我的问题的严重程度。

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


2
投票

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

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

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

1
投票

我猜您的子域有另一个网络根目录,如果是这样,只需指定该网络根目录。在您的示例中,

both static.domain.com
domain.com
具有相同的网络根目录。

来自 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


0
投票

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

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

0
投票

就我而言,我拒绝通过

访问安全相关文件(
/.htaccess
/.htpasswd

等)
location ~ /\. {
  deny all;
}

我改成了

location ~ /\.ht {
  deny all;
}

0
投票

我不想不必要地重复事情,但似乎有一些不同的情况可能会导致证书续订时出现 403 错误。对我来说,这与由于 WordPress / url 重写而改变的 nginx 配置有关。顺便说一句,使用 Virtualmin 上面的评论中有一个链接引用了 Github 上的问题。

一个人出色地解释了 nginx 中位置匹配的工作原理,并给出了 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 专家,所以我鼓励您阅读这篇文章并检查您的情况需要哪些参数。


0
投票
CAA

记录出现问题。

我已经发现了这个错误,这一点很清楚:

Certbot failed to authenticate some domains (authenticator: webroot). The Certificate Authority reported these problems: Domain: mydomain.com Type: caa Detail: CAA record for mydomain.com prevents issuance

删除 CAA 记录,一切正常

© www.soinside.com 2019 - 2024. All rights reserved.