Traefik,多个前端规则到一个 docker 容器

Traefik,multiple frontend rules to one docker container

我确实搜索了手册,但确实无法说得很清楚,甚至使用关键字google。

我需要将 /_ 代理到 API 容器,一些类似的规则 www.mydomain.com/_ => API container

已经有指向此 API 容器的指定域 api.mydomain.com => API container

这是我的 docker-compose.yml,我只想添加一条规则,将 /_ 也代理到此容器。

version: '3.3'

services:

  testapi:

    image: git.xxxx.com/api/core/test:latest

    restart: always

    networks:
      - web
      - default

    expose:
      - "80"

    labels:
      - "traefik.enable=true"
      - "traefik.port=80"
      - "traefik.docker.network=web"
      - "traefik.backend=testapi"
      #this domain is used for app
      - "traefik.frontend.rule=Host:api.test.mydomain.com"
      #this is used for website.All I want is prxy "https://www.test.mydomain.com/_/" to this container
      - "traefik.frontend.rule1=Host:www.test.mydomain.com;PathPrefixStrp:/_"

您可以使用细分标签:

version: '3.3'

services:
 testapi:
   image: git.xxxx.com/api/core/test:latest
   restart: always
   networks:
     - web
     - default
   expose:
     - "80"
   labels:
     - "traefik.enable=true"
     - "traefik.port=80"
     - "traefik.docker.network=web"
     #this domain is used for app
     - "traefik.foo.frontend.rule=Host:api.test.mydomain.com"
     - "traefik.bar.frontend.rule=Host:www.test.mydomain.com,m.test.mydomain.com;PathPrefixStrp:/_"

https://docs.traefik.io/v1.6/configuration/backends/docker/#on-containers-with-multiple-ports-segment-labels