letsencrypt webroot为位于docker中的nginx提供了404

问题描述 投票:1回答:1

我有一个简单的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时,我可以看到我的网站。

由于我将主机:/ 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目录中创建一个文件,并尝试公开下载该文件;但是,出于某种原因,它没有看到我的文件。

docker nginx certbot
1个回答
1
投票

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

Certbot将为极限挑战创建子文件夹,在您的情况下,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;
  }
© www.soinside.com 2019 - 2024. All rights reserved.