首页 > 解决方案 > Traefik 2 如何在静态配置中引用 tls 证书以在 docker-compose 文件中进行路由

问题描述

我在我的traefik_v2.yml

api: 
  dashboard: true
  insecure: true
global: {}
providers:
  providersThrottleDuration: 2s
  docker:
    watch: true
    endpoint: unix:///var/run/docker.sock
    swarmModeRefreshSeconds: 15s
  file:
    filename: "traefik_v2.yml"
log:
  level: INFO
tls:
  certificates:
    - certFile: /run/secrets/cert_secret
      keyFile: /run/secrets/cert_key_secret
entryPoints:
  web:
    address: ":80"
    redirections:
      entrypoint:
        to: external
        scheme: https
  web-secure:
    address: ":443"
  api:
    address: ":8080"
  external:
    address: ":10443"

现在在我的一个撰写文件中,如何将路由器 tls 配置配置为静态文件中存在的配置traefik_v2.yml

    version: '3.4'

    services:

      x-authentication-app:
        image: x_authentication_app_nightly:v${BUILD_NUMBER}
        deploy:
          labels:
            - "traefik.docker.network=x-swarm-net"
            - "traefik.http.routers.authenticationapp.rule=PathPrefix(`/authentication`)"    
            - "traefik.http.routers.authenticationapp.service=x-authentication-app"    
            - "traefik.http.routers.authenticationapp.entrypoints=web"   
            - "traefik.http.routers.authenticationapp.tls={}" // **What to say in here ? I want to use the static configurations that I created for tls in the traefik_v2.yml**
            - "traefik.enable=true"
            - "traefik.port=80"
          replicas: 1
          update_config:
            parallelism: 1
            delay: 10s
            order: stop-first
        networks:
          - default

    networks:
      default:
        external:
          name: x-swarm-net

标签: dockertraefik

解决方案


您无需多说什么,只需设置即可traefik.http.routers.authenticationapp.tls=true

您还需要让端点监听端口 443:

traefik.http.routers.authenticationapp.entrypoints=web, web-secure


推荐阅读