Traefik,对一个Docker容器的多个前端规则

时间:2018-09-09 02:11:13

标签: docker-compose traefik

我确实搜索了手册,但即使使用关键字在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:/_"

1 个答案:

答案 0 :(得分:11)

您可以使用细分标签:

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