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

我有一个简单的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 

创build的服务运行没有问题。 我添加了代理传递给同一networking中另一个服务的示例configuration(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装载到容器:/ var / webroot,我在/ opt / nginx / webroot中创build了一个名为“test.html”的文件(文件的内容无关紧要)。

当我打开我的浏览器并input:

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