首页 > 解决方案 > docker-compose 中的 Traefik 自签名证书通配符子域

问题描述

我正在寻找一种解决方案,让 traefik 为我的服务生成通配符证书。事实上,在本地开发中,我确实有多个服务共享同一个域,目前我必须接受每个服务的证书。

我有 2 个子域front.domain.localhostapi.domain.localhost并且我想为这两个子域提供一个证书。

这是一个演示docker-compose.yml

version: '3'

services:
  traefik:
    image: traefik:2.5
    command:
      - --providers.docker
      - --entryPoints.http.address=:80
      - --entryPoints.http.http.redirections.entryPoint.to=https
      - --entryPoints.http.http.redirections.entryPoint.scheme=https
      - --entryPoints.https.address=:443
    labels:
      - traefik.enable=true
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  front:
    image: traefik/whoami
    labels:
      - traefik.http.routers.front_router.rule=Host(`front.domain.localhost`)
      - traefik.http.routers.front_router.entrypoints=https
      - traefik.http.routers.front_router.tls=true

  api:
    image: traefik/whoami
    labels:
      - traefik.http.routers.api_router.rule=Host(`api.domain.localhost`)
      - traefik.http.routers.api_router.entrypoints=https
      - traefik.http.routers.api_router.tls=true

有了这个,我应该接受 2 个证书(每个子域一个)。

我尝试了各种组合,mainsanshttps://doc.traefik.io/traefik/routing/routers/#domains 中所述,没有成功。

我怎样才能做到这一点?

标签: dockerdocker-composetraefiktls1.3

解决方案


推荐阅读