Docker环境下使用Certbot为Nginx生成SSL证书失败的问题求助
Docker环境下使用Certbot为Nginx生成SSL证书失败的问题求助
大家好,我目前在VPS上用Docker部署了一个Nginx站点,想通过Certbot申请SSL证书,但卡在了webroot路径的环节,想请教下各位前辈哪里出了问题。
我在VPS里创建了一个名为live的目录,里面的文件结构如下:
- docker-compose.yml
- web/Dockerfile
- web/index.html
- config/nginx/conf.d/default.conf
- letsencrypt/
docker-compose.yml 配置内容
version: "3.8" services: web: build: context: "./web" dockerfile: "Dockerfile" ports: - "80:80" container_name: "web" volumes: - "./config/nginx/conf.d:/etc/nginx/conf.d" certbot: image: "certbot/certbot" volumes: - "./letsencrypt:/etc/letsencrypt" command: certonly
Nginx 配置文件(default.conf)
server { listen 80; server_name mydomain.com www.mydomain.com; location / { root /usr/share/nginx/html; index index.html index.htm; } location /.well-known/acme-challenge/ { root /usr/share/nginx/html; allow all; try_files $uri =404; } }
我的操作步骤
- 先执行
docker compose build web构建镜像 - 再用
docker compose up -d web启动web服务,访问我的域名能正常看到index.html的内容,这部分是没问题的。
遇到的问题
当我运行docker compose run certbot执行证书申请脚本时,流程走到需要指定--webroot路径的步骤,我输入/usr/share/nginx/html后,证书申请就是不成功,实在搞不懂哪里出错了,麻烦各位帮忙分析下~
备注:内容来源于stack exchange,提问作者Zoumath
相关产品推荐
相关产品推荐

