【问题标题】:letsencrypt webroot gives 404 for nginx located in dockerletsencrypt webroot 为位于 docker 中的 nginx 提供 404
【发布时间】:2017-10-04 23:20:30
【问题描述】:

我有一个简单的 docker 容器以下列方式运行:

docker service create --name nginx_proxy \
  --mount type=bind,source=/opt/nginx/conf.d,target=/etc/nginx/conf.d \
  --mount type=bind,source=/opt/nginx/webroot,target=/var/webroot \
  --constraint 'node.role==manager' \
  --publish 80:80 --publish 443:443 \
  --network nginx-net \
  nginx

创建的服务运行没有问题。我添加了代理传递给同一网络中另一个服务的示例配置(example.com.conf):

server {
  listen 80;
  server_name example.com www.example.com;
  location /.well-known/acme-challenge {
    alias /var/webroot;
  }

  location / {
    proxy_pass http://example_site:8080;
  }
}

当我访问 (www.)example.com 时,我可以看到我的网站。

由于我将 host:/opt/nginx/webroot 挂载到 container:/var/webroot,我在 /opt/nginx/webroot 中创建了一个名为“test.html”的文件(文件内容无关紧要)。

当我打开浏览器并输入:

http://example.com/.well-known/acme-challenge/test.html

我可以查看我添加到 /opt/nginx/webroot 的文件。但是,当我运行以下命令时,certbot 会抛出 404:

certbot certonly --dry-run --webroot -w /opt/nginx/webroot -d example.com -d www.example.com

我在这里缺少什么?据我了解,certbot 在 webroot 目录中创建了一个文件并尝试公开下载该文件;但是,由于某种原因,它没有看到我的文件。

【问题讨论】:

  • 能发下certbot和nginx的日志吗?

标签: docker nginx certbot


【解决方案1】:

我相信您的问题可能是由于对 certbot 命令中的 -w 有误解。 -w 或 --webroot-path 指定包含您的网络服务器提供的文件的顶级目录。

Certbot 将为 acme-challenge 创建子文件夹,在您的情况下,certbot 将创建 /opt/nginx/webroot/.well-known/acme-challenge/ 但您的 nginx 配置指向 webroot 本身。

https://certbot.eff.org/docs/using.html#webroot

考虑改变

  location /.well-known/acme-challenge {
    alias /var/webroot;
  }

这样的事情

  location /.well-known/acme-challenge {
    alias /var/webroot/.well-known/acme-challenge;
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-15
    • 2015-08-12
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    • 2019-12-04
    • 2019-04-21
    • 2020-12-31
    相关资源
    最近更新 更多