Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Traefik,multiple frontend rules to one docker container

I did search the manual but really couldn't make it very clear, even using the keywords to google that.

I need to proxy the /_ to the API container, some rule like that www.mydomain.com/_ => API container

There is already a specified domain point to this API container api.mydomain.com => API container

This is my docker-compose.yml, all I want is to add a rule that proxy the /_ to this container too.

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:/_"
like image 729
wanfujinan Avatar asked Sep 09 '18 02:09

wanfujinan


1 Answers

You can use segment labels:

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

like image 141
ldez Avatar answered Sep 19 '22 16:09

ldez