You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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;
    }
}

我的操作步骤

  1. 先执行docker compose build web构建镜像
  2. 再用docker compose up -d web启动web服务,访问我的域名能正常看到index.html的内容,这部分是没问题的。

遇到的问题

当我运行docker compose run certbot执行证书申请脚本时,流程走到需要指定--webroot路径的步骤,我输入/usr/share/nginx/html后,证书申请就是不成功,实在搞不懂哪里出错了,麻烦各位帮忙分析下~

备注:内容来源于stack exchange,提问作者Zoumath

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 12:18:00