Rule to match any path except

I ave an image hosting the frontend and one hosting the backend. I would like to route all traffic to the frontend except traffic to path /graphql.

My initial try was to do it like this:

version: "3"

services:
  reverse-proxy:
    image: traefik:v2.0.0
    command:
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  frontend:
    image: my/frontend
    labels:
      traefik.enable: true
      traefik.http.routers.frontend.rule: Host(`example.com`)
      traefik.http.services.frontend.loadbalancer.server.port: 3000

  backend:
    image: my/backend
    labels:
      traefik.enable: true
      traefik.http.routers.backend.rule: Host(`example.com`) && Path(`/graphql`)
      traefik.http.services.backend.loadbalancer.server.port: 4000

However with that the frontend container gets all the traffic.. Even traffic to example.com/graphql..

How can I set this up?

Hello,

I try with this docker-compose file (adapted from your docker-compose file):

version: '3.5'

services:

  traefik:
    image: traefik:v2.0.0
    ports:
      - 80:80
    command:
      - --log.level=DEBUG
      - --api
      - --entrypoints.web.address=:80
      - --providers.docker.exposedbydefault=false

    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.rule=Host(`traefik.docker.localhost`)"
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.entrypoints=web"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

  frontend:
    image: containous/whoami:v1.3.0
    labels:
      traefik.enable: true
      traefik.http.routers.frontend.rule: Host(`one.docker.localhost`)
      # traefik.http.services.frontend.loadbalancer.server.port: 3000

  backend:
    image: containous/whoami:v1.3.0
    labels:
      traefik.enable: true
      traefik.http.routers.backend.rule: Host(`one.docker.localhost`) && Path(`/graphql`)
      # traefik.http.services.backend.loadbalancer.server.port: 4000

I have the expected behavior, so I don't reproduce your problem.

Hello,
maybe is to late for your request, but maybe it will be usefull for for someone else

from v2.5 traefik Support not in rules definition (#8164 by juliens)

for example, you can use !Host , !Path ....

1 Like