美文网首页Traefik
traefik v1 迁移 到treafik v2.0.0 配置

traefik v1 迁移 到treafik v2.0.0 配置

作者: 思考蛙 | 来源:发表于2019-09-30 16:29 被阅读0次
    traefikee.logo.cluster.flat.png

    traefik v1 与 v2 版本的配置差别很大,属于破坏是更新,要注意的是 static 配置与 dynamic 配置分为两个文件

    docker-compose.yml 配置

    version: '3'
     
    services:
      reverse-proxy:
        image: traefik:v2.0.0
        container_name: "traefik"
        ports:
          - 80:80
          - 8000:8000
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - ./traefik.toml:/traefik.toml
          # - /traefik/acme.json:/acme.json
          # - /var/log/traefik:/var/log
          - ./dynamic_conf.toml:/dynamic_conf.toml
      whoami:
        # A container that exposes an API to show its IP address
        image: containous/whoami
        labels:
          # 声明公开此容器访问
          - "traefik.enable=true"
          # 服务将响应的域
          - "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"
          # 只允许来自预定义的入口点“web”的请求
          - "traefik.http.routers.whoami.entrypoints=web"
    

    traefik.toml 的配置

    ## traefik.toml
    ## Static configuration
    
    [entryPoints]
      [entryPoints.web]
        address = ":80"
    
      [entryPoints.https]
        address = ":443"
    
      [entryPoints.traefik]
        address = ":8000"
    
    [providers]
      [providers.docker]
        exposedByDefault = false
      [providers.file]
        filename = "dynamic_conf.toml"
        # watch = true
    
    [retry]
    
    [api]
      dashboard = true
      insecure = true
      #debug = true
     
    [ping]
    

    dynamic_conf.yml 的配置

    ## dynamic_conf.toml
    ## Dynamic configuration
    
    [http.routers.my-api]
        entryPoints = ["traefik"]
        rule = "PathPrefix(`/dashboard`) || PathPrefix(`/api`)"
        service = "api@internal"
        middlewares = ["auth"]
    
    [http.middlewares.auth.basicAuth]
      users = [
        "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", 
      ]
    

    相关文章

      网友评论

        本文标题:traefik v1 迁移 到treafik v2.0.0 配置

        本文链接:https://www.haomeiwen.com/subject/qewuuctx.html