跳转到主要内容

traefik-gateway-dashboard

本文为dashboard用法,基础用法请参考:traefik-gateway

重要bug提醒:截止至2023-06-22,如果动态创建的服务发现,少于1个中间件,则会出错,既需要保证整个项目至少要有一个中间件。可以随便写一个,但是必须要有一个。

三个镜像

  • traefik
    • push swr.cn-south-1.myhuaweicloud.com/vp-whdev/all-in-devops/traefik:202306051
内置插件:rewritebody
内置插件:rewriteHeaders
  • 动态服务发现:

    • swr.cn-south-1.myhuaweicloud.com/vp-whdev/all-in-devops/traefik-service-discovery:20230628

    更新日志:2023-06-28

    • 动态服务发现静态资源添加服务监控前端代码
    • 修复镜像包运行entrypoint.sh文件不存在问题
    • mysql数据脚本调整

    更新日志:2023-06-26

    修改内置插件偶尔会失效的问题

    • 动态服务发现

      • swr.cn-south-1.myhuaweicloud.com/vp-whdev/all-in-devops/traefik-service-discovery:202306051

      更新日志:2023-06-21:

      • 打包dashboard面板到一个服务,无需再部署dashboard
      • 增加服务监控
    • dashboard面板:

      • swr.cn-south-1.myhuaweicloud.com/vp-whdev/all-in-devops/traefik-service-discovery-dashboard-front:stage

      更新日志:2023-06-21

      • dashboard面板已经集成到动态服务发现,无需部署

    安装部署说明

    • 部署: traefik
    # 建议服务名:traefik-gateway
    # 端口开放
    # 80,http端口
    # 443,https端口
    # 8080,traefik自带的dashboard端口,可以不开放
    
    • 部署traefik-service-discovery
    # 服务名必须为 traefik-service-discovery
    
    
    # 端口开放
    # 8080,非必须
    
    # 环境变量
    spring.profiles.active = mysqlProd
    # mysqlProd,使用mysql数据库,prod,使用sqlite数据库
    # 如果使用sqlite数据库,需要注意数据库持久化路径,容器目录/data,容器初始化时会自动复制初始化数据库文件。
    # sqlite不支持服务监控
    
    app.datasource.host =
    app.datasource.name=
    app.datasource.password =
    app.datasource.username =
    
    
    • 数据库初始化脚本
    CREATE TABLE `traefik_gateway_config` (
      `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
      `route_name` varchar(255) DEFAULT NULL COMMENT '路由名称',
      `access_path` varchar(255) DEFAULT NULL COMMENT '访问路径',
      `service_type` int(2) DEFAULT NULL COMMENT '后端服务类型: 1:http 2:tcp 3:udp',
      `service_address` varchar(255) DEFAULT NULL COMMENT '后端服务地址',
      `middleware` text COMMENT '中间件',
      `status` int(255) DEFAULT NULL COMMENT '启用/禁用状态: 0:禁用 1:启用',
      `deleted` int(255) DEFAULT '0' COMMENT '删除状态: 0:不删除 1:删除',
      PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='网关配置';
    
    CREATE TABLE `global_middleware` (
      `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
      `global_middleware` longtext COMMENT '全局中间件',
      PRIMARY KEY (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='全局中间件';
    
    DROP TABLE IF EXISTS `QRTZ_JOB_DETAILS`;
    CREATE TABLE QRTZ_JOB_DETAILS(
      SCHED_NAME VARCHAR(120) NOT NULL,
      JOB_NAME VARCHAR(200) NOT NULL,
      JOB_GROUP VARCHAR(200) NOT NULL,
      DESCRIPTION VARCHAR(250) NULL,
      JOB_CLASS_NAME VARCHAR(250) NOT NULL,
      IS_DURABLE VARCHAR(1) NOT NULL,
      IS_NONCONCURRENT VARCHAR(1) NOT NULL,
      IS_UPDATE_DATA VARCHAR(1) NOT NULL,
      REQUESTS_RECOVERY VARCHAR(1) NOT NULL,
      JOB_DATA BLOB NULL,
      PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP))
      ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
    
    DROP TABLE IF EXISTS `QRTZ_TRIGGERS`;
    CREATE TABLE QRTZ_TRIGGERS (
      SCHED_NAME VARCHAR(120) NOT NULL,
      TRIGGER_NAME VARCHAR(200) NOT NULL,
      TRIGGER_GROUP VARCHAR(200) NOT NULL,
      JOB_NAME VARCHAR(200) NOT NULL,
      JOB_GROUP VARCHAR(200) NOT NULL,
      DESCRIPTION VARCHAR(250) NULL,
      NEXT_FIRE_TIME BIGINT(13) NULL,
      PREV_FIRE_TIME BIGINT(13) NULL,
      PRIORITY INTEGER NULL,
      TRIGGER_STATE VARCHAR(16) NOT NULL,
      TRIGGER_TYPE VARCHAR(8) NOT NULL,
      START_TIME BIGINT(13) NOT NULL,
      END_TIME BIGINT(13) NULL,
      CALENDAR_NAME VARCHAR(200) NULL,
      MISFIRE_INSTR SMALLINT(2) NULL,
      JOB_DATA BLOB NULL,
      PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
      FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
      REFERENCES QRTZ_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP))
      ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
    
    DROP TABLE IF EXISTS `QRTZ_SIMPLE_TRIGGERS`;
    CREATE TABLE QRTZ_SIMPLE_TRIGGERS (
      SCHED_NAME VARCHAR(120) NOT NULL,
      TRIGGER_NAME VARCHAR(200) NOT NULL,
      TRIGGER_GROUP VARCHAR(200) NOT NULL,
      REPEAT_COUNT BIGINT(7) NOT NULL,
      REPEAT_INTERVAL BIGINT(12) NOT NULL,
      TIMES_TRIGGERED BIGINT(10) NOT NULL,
      PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
      FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
      REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP))
      ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
    
    DROP TABLE IF EXISTS `QRTZ_CRON_TRIGGERS`;
    CREATE TABLE QRTZ_CRON_TRIGGERS (
      SCHED_NAME VARCHAR(120) NOT NULL,
      TRIGGER_NAME VARCHAR(200) NOT NULL,
      TRIGGER_GROUP VARCHAR(200) NOT NULL,
      CRON_EXPRESSION VARCHAR(120) NOT NULL,
      TIME_ZONE_ID VARCHAR(80),
      PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
      FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
      REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP))
      ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
    
    DROP TABLE IF EXISTS `QRTZ_SIMPROP_TRIGGERS`;  
    CREATE TABLE QRTZ_SIMPROP_TRIGGERS
    (
      SCHED_NAME VARCHAR(120) NOT NULL,
      TRIGGER_NAME VARCHAR(200) NOT NULL,
      TRIGGER_GROUP VARCHAR(200) NOT NULL,
      STR_PROP_1 VARCHAR(512) NULL,
      STR_PROP_2 VARCHAR(512) NULL,
      STR_PROP_3 VARCHAR(512) NULL,
      INT_PROP_1 INT NULL,
      INT_PROP_2 INT NULL,
      LONG_PROP_1 BIGINT NULL,
      LONG_PROP_2 BIGINT NULL,
      DEC_PROP_1 NUMERIC(13,4) NULL,
      DEC_PROP_2 NUMERIC(13,4) NULL,
      BOOL_PROP_1 VARCHAR(1) NULL,
      BOOL_PROP_2 VARCHAR(1) NULL,
      PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
      FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
      REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP))
      ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
    
    DROP TABLE IF EXISTS `QRTZ_BLOB_TRIGGERS`;
    CREATE TABLE QRTZ_BLOB_TRIGGERS (
      SCHED_NAME VARCHAR(120) NOT NULL,
      TRIGGER_NAME VARCHAR(200) NOT NULL,
      TRIGGER_GROUP VARCHAR(200) NOT NULL,
      BLOB_DATA BLOB NULL,
      PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
      INDEX (SCHED_NAME,TRIGGER_NAME, TRIGGER_GROUP),
      FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
      REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP))
      ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
    
    DROP TABLE IF EXISTS `QRTZ_CALENDARS`;
    CREATE TABLE QRTZ_CALENDARS (
      SCHED_NAME VARCHAR(120) NOT NULL,
      CALENDAR_NAME VARCHAR(200) NOT NULL,
      CALENDAR BLOB NOT NULL,
      PRIMARY KEY (SCHED_NAME,CALENDAR_NAME))
      ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
    
    DROP TABLE IF EXISTS `QRTZ_PAUSED_TRIGGER_GRPS`;  
    CREATE TABLE QRTZ_PAUSED_TRIGGER_GRPS (
      SCHED_NAME VARCHAR(120) NOT NULL,
      TRIGGER_GROUP VARCHAR(200) NOT NULL,
      PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP))
      ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
    
    DROP TABLE IF EXISTS `QRTZ_FIRED_TRIGGERS`;
    CREATE TABLE QRTZ_FIRED_TRIGGERS (
      SCHED_NAME VARCHAR(120) NOT NULL,
      ENTRY_ID VARCHAR(95) NOT NULL,
      TRIGGER_NAME VARCHAR(200) NOT NULL,
      TRIGGER_GROUP VARCHAR(200) NOT NULL,
      INSTANCE_NAME VARCHAR(200) NOT NULL,
      FIRED_TIME BIGINT(13) NOT NULL,
      SCHED_TIME BIGINT(13) NOT NULL,
      PRIORITY INTEGER NOT NULL,
      STATE VARCHAR(16) NOT NULL,
      JOB_NAME VARCHAR(200) NULL,
      JOB_GROUP VARCHAR(200) NULL,
      IS_NONCONCURRENT VARCHAR(1) NULL,
      REQUESTS_RECOVERY VARCHAR(1) NULL,
      PRIMARY KEY (SCHED_NAME,ENTRY_ID))
      ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
    
    DROP TABLE IF EXISTS `QRTZ_SCHEDULER_STATE`;
    CREATE TABLE QRTZ_SCHEDULER_STATE (
      SCHED_NAME VARCHAR(120) NOT NULL,
      INSTANCE_NAME VARCHAR(200) NOT NULL,
      LAST_CHECKIN_TIME BIGINT(13) NOT NULL,
      CHECKIN_INTERVAL BIGINT(13) NOT NULL,
      PRIMARY KEY (SCHED_NAME,INSTANCE_NAME))
      ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
    
    DROP TABLE IF EXISTS `QRTZ_LOCKS`;
    CREATE TABLE QRTZ_LOCKS (
      SCHED_NAME VARCHAR(120) NOT NULL,
      LOCK_NAME VARCHAR(40) NOT NULL,
      PRIMARY KEY (SCHED_NAME,LOCK_NAME))
      ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
    
    CREATE INDEX IDX_QRTZ_J_REQ_RECOVERY ON QRTZ_JOB_DETAILS(SCHED_NAME,REQUESTS_RECOVERY);
    CREATE INDEX IDX_QRTZ_J_GRP ON QRTZ_JOB_DETAILS(SCHED_NAME,JOB_GROUP);
    
    CREATE INDEX IDX_QRTZ_T_J ON QRTZ_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP);
    CREATE INDEX IDX_QRTZ_T_JG ON QRTZ_TRIGGERS(SCHED_NAME,JOB_GROUP);
    CREATE INDEX IDX_QRTZ_T_C ON QRTZ_TRIGGERS(SCHED_NAME,CALENDAR_NAME);
    CREATE INDEX IDX_QRTZ_T_G ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP);
    CREATE INDEX IDX_QRTZ_T_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE);
    CREATE INDEX IDX_QRTZ_T_N_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_STATE);
    CREATE INDEX IDX_QRTZ_T_N_G_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP,TRIGGER_STATE);
    CREATE INDEX IDX_QRTZ_T_NEXT_FIRE_TIME ON QRTZ_TRIGGERS(SCHED_NAME,NEXT_FIRE_TIME);
    CREATE INDEX IDX_QRTZ_T_NFT_ST ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE,NEXT_FIRE_TIME);
    CREATE INDEX IDX_QRTZ_T_NFT_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME);
    CREATE INDEX IDX_QRTZ_T_NFT_ST_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_STATE);
    CREATE INDEX IDX_QRTZ_T_NFT_ST_MISFIRE_GRP ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_GROUP,TRIGGER_STATE);
    
    CREATE INDEX IDX_QRTZ_FT_TRIG_INST_NAME ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME);
    CREATE INDEX IDX_QRTZ_FT_INST_JOB_REQ_RCVRY ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME,REQUESTS_RECOVERY);
    CREATE INDEX IDX_QRTZ_FT_J_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP);
    CREATE INDEX IDX_QRTZ_FT_JG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_GROUP);
    CREATE INDEX IDX_QRTZ_FT_T_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);
    CREATE INDEX IDX_QRTZ_FT_TG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_GROUP);
    
    DROP TABLE IF EXISTS `traefik_alarm_log`;
    CREATE TABLE `traefik_alarm_log` (
      `id` varchar(32) NOT NULL DEFAULT '0' COMMENT '主键id',
      `project_id` varchar(32) DEFAULT NULL COMMENT '项目ID',
      `service_id` varchar(32) DEFAULT NULL COMMENT '服务ID',
      `receive_mobile` varchar(255) DEFAULT NULL COMMENT '接收手机号',
      `receive_email` varchar(255) DEFAULT NULL COMMENT '接收邮箱',
      `send_state` tinyint(1) DEFAULT NULL COMMENT '发送状态 0:成功 1:失败',
      `alarm_time` datetime DEFAULT NULL COMMENT '报警时间',
      `err_msg` text COMMENT '错误信息',
      PRIMARY KEY (`id`)
    ) COMMENT='服务报警日志';
    
    DROP TABLE IF EXISTS `traefik_monitor_contacts`;
    CREATE TABLE `traefik_monitor_contacts` (
      `id` varchar(32) NOT NULL DEFAULT '0' COMMENT '主键id',
      `project_id` varchar(32) DEFAULT NULL COMMENT '项目ID',
      `contacts` varchar(64) DEFAULT NULL COMMENT '联系人',
      `contact_type` tinyint(1) DEFAULT NULL COMMENT '联系方式(1:手机,2:邮箱)',
      `contact_no` varchar(128) DEFAULT NULL COMMENT '联系号码',
      PRIMARY KEY (`id`)
    ) COMMENT='项目联系人';
    
    DROP TABLE IF EXISTS `traefik_project_management`;
    CREATE TABLE `traefik_project_management` (
      `id` varchar(32) NOT NULL DEFAULT '0' COMMENT '主键id',
      `project_name` varchar(64) DEFAULT NULL COMMENT '项目名称',
      `threshold` int(2) DEFAULT NULL COMMENT '阈值',
      `monitoring_frequency` tinyint(5) DEFAULT NULL COMMENT '监控频率',
      `status` tinyint(1) DEFAULT '0' COMMENT '启用/禁用状态: 0:禁用 1:启用',
      `job_id` varchar(32) DEFAULT NULL COMMENT '定时任务ID',
      `deleted` int(255) DEFAULT '0' COMMENT '删除状态: 0:未删除 1:删除',
      `create_time` datetime DEFAULT NULL COMMENT '创建时间',
      PRIMARY KEY (`id`)
    ) COMMENT='项目管理';
    
    DROP TABLE IF EXISTS `traefik_service_monitor`;
    CREATE TABLE `traefik_service_monitor` (
      `id` varchar(32) NOT NULL DEFAULT '0' COMMENT '主键id',
      `project_id` varchar(32) DEFAULT NULL COMMENT '项目ID',
      `sevice_name` varchar(64) DEFAULT NULL COMMENT '服务名称',
      `listening_address` varchar(255) DEFAULT NULL COMMENT '监听接口地址',
      `service_type` tinyint(1) DEFAULT '1' COMMENT '接口类型: 0:POST 1:GET',
      `status` tinyint(1) DEFAULT '0' COMMENT '启用/禁用状态: 0:禁用 1:启用',
      `deleted` int(255) DEFAULT '0' COMMENT '删除状态: 0:未删除 1:删除',
      `delete_time` datetime DEFAULT NULL COMMENT '删除时间',
      `latest_alarm_time` datetime DEFAULT NULL COMMENT '最新报警时间',
      `create_time` datetime DEFAULT NULL COMMENT '创建时间',
      `service_status` tinyint(1) DEFAULT '0' COMMENT '服务状态: 0:成功 1:失败',
      `restart_number` int(6) DEFAULT '0' COMMENT '失败重启次数',
      PRIMARY KEY (`id`)
    ) COMMENT='服务监听';
    
    
    • traefik-service-discovery-dashboard-fron
    # 2023-06-21,本服务已经集成到traefik-service-discovery,不需要部署
    # 端口开放:80
    # 访问路径/front/
    
    • 负载均衡配置
    路径 服务 说明 备注
    / traefik 网站根目录 必须
    /traefik-dashboard/ traefik traefik内置的dashboard 非必须,如果没有配置网站根目录则需要
    /traefikconfig-dashboard/ traefik traefik动态路由dashboard 非必须,如果没有配置网站根目录则需要
    /traefik-service-discovery/ traefik 动态路由api 非必须,如果没有配置网站根目录则需要

    首页不是从根目录开始

    如果你的首页不是从根目录开始,则需要做一些单独的配置,实现原理为,将dashboard需要用到的3个路径处理为所需要的目录。

    复制下面的配置文件,挂载到traefik-gatewy的容器路径

    # 使用k8s集群时,建议使用配置映射卷
    
    ./index-not-root.yaml:/etc/traefik/conf.d/conf2/index-not-root.yaml
    
    

    需要在负载均衡加入配置

    路径 服务 说明 备注
    /minio/ traefik 业务路由入口 必须
    /_minio/ traefik 面板路由入口 如果配置了下面三个路径,则是非必须
    /_minio/traefik-dashboard/ traefik traefik内置的dashboard 非必须,如果没有配置面板入口则需要
    /_minio/traefikconfig-dashboard/ traefik 动态路由dashboard 非必须,如果没有配置面板入口则需要
    /_minio/traefik-service-discovery/ traefik 动态路由api 非必须,如果没有配置面板入口则需要
    
    http:
      routers:
        # 首页不是根目录
        index-not-root:
        # 注意路由匹配前缀,填写你的实际路径,为了保证一致性,建议本服务使用 _ 开头
        # 注意中间件中的路径前缀,应该和路由路径一致,
        # 注意重写header的前缀,应该和路由路径一致。
        # 根据本路由规则,可以看出是将服务又重定向到traefik-gateway,即多了一层不必要的代理,会带来性能损失。
        # 由此,这个额外的路由,只应该用于处理traefik控制面板
        # 真正的服务不应该由此处理,而应该直接指向到traefik-gateway
        # 既你需要配置面板路由路径,应该与你的服务路径,使用不通的名称
        # 本次使用的是 _minio ,请将本文的_minio 替换为你需要的
          # rule: "PathPrefix(`/_minio/`)" 
        # 2023-06-22,:只处理dashboard相关的3个路径,以开启面板,业务路由在面板进行配置,以解决多了一层代理问题   
          rule: "PathPrefix(`/_minio/traefik-dashboard/`) || PathPrefix(`/_minio/traefikconfig-dashboard/`) || PathPrefix(`/_minio/traefik-service-discovery/`)"  
          service: index-not-root
          middlewares:
            - stripPrefix-index-not-root
            - rewritebody-index-not-root
            - rewriteHeaders-index-not-root
      services:
        index-not-root:
          loadBalancer:
            servers:
              - url: http://traefik-gateway:80    # 部署的traefik主程序必须叫这个名字或者修改为实际部署的名字
      middlewares:
      # 去除前缀  
        stripPrefix-index-not-root:
          stripPrefix:
            prefixes:
              - "/_minio/"
      # 正文路径改写
        rewritebody-index-not-root:
          plugin:
            plugin-rewritebody:                   # 要和静态配置文件的插件名称对应上
              rewrites:
                - regex: "/traefik-service-discovery/api/"
                  replacement: "/_minio/traefik-service-discovery/api/"
                - regex: "/traefik-dashboard/api"
                  replacement: "/_minio/traefik-dashboard/api"
                - regex: "/_minio/dashboard/"
                  replacement: "/_minio/traefik-dashboard/dashboard/"
      # Header重定向改写
        rewriteHeaders-index-not-root:
          plugin:
            plugin-rewriteHeaders:                # 要和静态配置文件的插件名称对应上
              rewrites:
                - header: "Location"
                  regex: "/_minio/dashboard/"
                  replacement: "/_minio/traefik-dashboard/dashboard/"
    
    
    
    

    插件使用

    插件参考网址

    middlewares:
    # 删除路径前前缀,traefik默认会把整个URL路径全部传过来,会导致与后端路径不一致,需要进行路径删除处理
      stripPrefix-traefikconfig-dashboard:
        stripPrefix:
          prefixes:
            - "/traefikconfig-dashboard/"
    
    # 增加路径前缀,对应与后端服务,即使在填写URL路径,traefik也不会处理后端路径,会导致与后端路径不一致,需要增加实际路径
      addPrefixFront-traefikconfig-dashboard:
        addPrefix:
          prefix: "/front/"
    
    # 正文路径改写,由于某些情况下服务没有使用相对路径,需要对在页面写死的路径进行正则替换
      rewritebody-traefikconfig-dashboard:
          plugin:
            plugin-rewritebody: # 要和静态配置文件的插件名称对应上,本镜像仅能使用这个名字
              rewrites:
                - regex: "/api/"
                  replacement: "/traefik-service-discovery/api/"   
    
    # 基础身份验证
      basicAuth-traefikconfig-dashboard:
          basicAuth:
            removeHeader: true
            users:
              - "admin:" # 在线生成 http://www.jsons.cn/htpasswd/
    
    
    # 发送到后端时修改header,例如后端限制了域名
      headers-peisong:
        headers:
          customRequestHeaders:
            host: "peisong.gxzszs.cn"
    
    # 重写 header,对响应的head进行处理,例如写死的重定向
      rewriteHeaders-peisong:
        plugin:
          plugin-rewriteHeaders: # 要和静态配置文件的插件名称对应上,本镜像仅能使用这个名字
            rewrites:
              - header: "Location"
                regex: "peisong.gxzszs.cn"
                replacement: "peisong.gxfusui.com"
              - header: "Location"
                regex: "http://peisong.gxfusui.com/plugin.php"
                replacement: "/plugin.php"