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

Traefik能否处理多证书/域名?新增wenote.me的配置咨询

复用现有Traefik处理新域名wenote.me的方案

当然可以复用你现有的Traefik实例来处理新域名wenote.me的流量!毕竟两个域名都由Cloudflare管理DNS和SSL,咱们只需要调整Traefik的配置,让它能识别新域名的请求并加载对应证书就行。下面给你两种配置方案,你可以根据自己的习惯选择:

方案一:延续现有手动证书配置风格

你原来的Traefik配置里,[[entryPoints.https.tls.certificates]]是数组结构,支持添加多组证书。只需要把从Cloudflare下载的wenote.me证书和私钥加进去就行:

defaultEntryPoints = ["http", "https"]
[web]
address = ":8080"
[web.auth.basic]
users = ["admin:xxx"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
# 原jstock.co域名的证书
[[entryPoints.https.tls.certificates]]
CertFile = "/app/cert.pem"
KeyFile = "/app/key.pem"
# 新增wenote.me域名的证书
[[entryPoints.https.tls.certificates]]
CertFile = "/app/wenote_cert.pem"
KeyFile = "/app/wenote_key.pem"

注意事项:

  • 把从Cloudflare导出的wenote.me证书文件(需包含完整证书链)和私钥文件放到Traefik容器能访问的路径下(比如和cert.pem同目录的/app/)
  • 确保对应Docker服务的Traefik路由标签配置正确,比如给wenote.me的服务添加:
    -l traefik.frontend.rule=Host:notification.wenote.me
    -l traefik.port=你的容器内部端口
    

方案二:自动获取&续期证书(更省心)

如果不想手动管理证书,咱们可以让Traefik和Cloudflare集成,自动通过Let's Encrypt获取证书并续期,全程不用手动下载证书。配置如下:

defaultEntryPoints = ["http", "https"]
[web]
address = ":8080"
[web.auth.basic]
users = ["admin:xxx"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]

# 开启ACME自动证书管理
[acme]
email = "你的邮箱@example.com" # 用于接收证书过期提醒
storage = "/app/acme.json" # 存储证书的文件,必须设置600权限
entryPoint = "https"
onHostRule = true # 自动为符合Host规则的域名生成证书
# 使用Cloudflare DNS挑战验证域名所有权
[acme.dnsChallenge]
provider = "cloudflare"
delayBeforeCheck = 0 # 按需调整等待时间

# 注意:Cloudflare的API凭证推荐通过环境变量传入,不要明文写在配置里

配置步骤:

  1. 创建acme.json文件,设置权限为600:chmod 600 /path/to/acme.json,否则Traefik无法写入证书
  2. 启动Traefik容器时,传入Cloudflare的API凭证作为环境变量:
    docker run -d \
      # 其他启动参数...
      -e CLOUDFLARE_EMAIL=你的Cloudflare登录邮箱 \
      -e CLOUDFLARE_API_KEY=你的Cloudflare全局API密钥 \
      traefik:你的版本号
    
  3. 同样要给wenote.me的Docker服务配置正确的Traefik路由标签,Traefik会自动识别并为其生成证书

这种方式的好处是,不管是jstock.co还是wenote.me的子域名,Traefik都会自动处理证书的申请和续期,完全不用你手动干预。

内容的提问来源于stack exchange,提问作者Cheok Yan Cheng

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 08:04:55