让我们加密失败的授权过程 - 码头工人



我正在尝试为我的网站设置 HTTPS 证书。由于我使用的是 docker 容器,因此我设置了以下配置

  1. Node 将公共内容提供给名为 static-content 的命名驱动程序
  2. 此驱动程序由 nginx 访问和服务

我的码头工人撰写文件

version : '2'
services:
nginx:
container_name: nginx
build: ./nginx/
ports:
- "80:80"
- "443:443"
links:
- web:web
volumes:
- /etc/letsencrypt/:/etc/letsencrypt/
- /etc/ssl:/etc/ssl
- static-content:/usr/src/app
web:
container_name: web
image: kannaj/42exp
env_file: .env
volumes:
- ./logs:/usr/src/app/logs
- static-content:/usr/src/app/public
expose:
- "8000"
environment:
- NODE_ENV=production
command: npm run package
volumes:
static-content:

运行docker volume inspect static-content显示以下内容

[
{
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/www_static-content/_data",
"Name": "www_static-content",
"Options": {},
"Scope": "local"
}
]

然后我跑sudo certbot certonly --force-renewal --webroot -w /var/lib/docker/volumes/www_static-content/_data -d 42exp.com -d www.42exp.com

但是我收到以下错误

Domain: 42exp.com
Type:   unauthorized
Detail: Invalid response from
http://42exp.com/.well-known/acme-challenge/KbQko2Y6lZfiDcbZ-dF7DTchX3G__wmZVMMn4xT8tjs
[139.162.21.71]: 404
Domain: www.42exp.com
Type:   unauthorized
Detail: Invalid response from
http://www.42exp.com/.well-known/acme-challenge/gHHrVOYg9OfLznO7SiH_HTo6A6SGLpUHYuJax1U65ws
[139.162.21.71]: 404

经过一些研究,我将以下内容添加到nginx中的服务器块中,假设certbot无法访问该域

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

我现在收到了不同的 404 响应

IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: www.42exp.com
Type:   unauthorized
Detail: Invalid response from
http://www.42exp.com/.well-known/acme-challenge/dWH2F9pApDnElq8jpqiykaylqUF7NR-RZ8MmWTg1NRA:
"<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>"
Domain: 42exp.com
Type:   unauthorized
Detail: Invalid response from
http://42exp.com/.well-known/acme-challenge/z_A7WOrYzEEu0RvmAFkgpNCz9ONNYByGc3RkdeqmJDo:
"<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.

我查看了一下我的静态内容文件夹,似乎确实有一个.well-known文件夹。我不确定为什么我仍然得到 404。 谁能帮忙?

原来我必须在这里包含一个根指令

location ~ /.well-known {
root /usr/src/app;
allow all;
}

如此线程中所述:

  • 您指定的网络根目录是否正确?
  • 如果你把一个文件放在/usr/src/app/.well-known/acme-challenge/test 你能在 http://www.42exp.com/.well-known/acme-challenge/test 访问它吗?

看起来该测试文件不存在,并且NGiNX返回404.html页面的内容。

如此处所示,certbot 路径可能不正确。请参阅本教程(不在 docker 上下文中,但仍然可以为您提供一些线索)

无论如何,请检查nginx日志以查看正在访问的内容。

你需要提到/.well-known 应该指向的地方:root/usr/src/app;
但请参阅"NGiNX 陷阱和常见错误">

root放在位置块内将起作用,并且完全有效。

问题是当您开始添加位置块时。如果向每个位置块添加root,则不匹配的地理位置块将没有根。

因此,在位置块之前出现root指令非常重要,如果需要,该指令可以覆盖此指令。

最新更新