【问题标题】:Lets encrypt failed authorization procedure - docker让我们加密失败的授权过程 - docker
【发布时间】:2017-10-20 23:25:41
【问题描述】:

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

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

我的 docker-compose 文件

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

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

  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。 有人可以帮忙吗?

【问题讨论】:

    标签: nginx docker docker-compose lets-encrypt


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      正如this thread中提到的:

      该测试文件似乎不存在,NGiNX 返回了404.html 页面的内容。

      作为seen here,certbot 路径可能不正确。见this tutorial(不在docker上下文中,但仍然可以给你一些线索)

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

      您需要提及 /.well-known 应该指向的位置:root /usr/src/app;
      但见“NGiNX Pitfalls and Common Mistakes

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

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

      因此,root 指令出现在您的位置块之前很重要,如果需要,它们可以覆盖该指令。

      【讨论】:

      • 原来我必须包含一个根指令以及“允许所有”命令。现在看起来工作正常。谢谢:)
      猜你喜欢
      • 2017-08-13
      • 2016-04-12
      • 1970-01-01
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多