【问题标题】:Traefik,multiple frontend rules to one docker containerTraefik,多个前端规则到一个 docker 容器
【发布时间】:2019-02-13 21:13:26
【问题描述】:

我确实搜索了手册,但确实无法说得很清楚,即使使用关键字谷歌搜索也是如此。

我需要将/_ 代理到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:/_"

【问题讨论】:

    标签: docker-compose traefik


    【解决方案1】:

    您可以使用分段标签:

    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

    【讨论】:

    • 像魅力一样工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    相关资源
    最近更新 更多