7

I have a reverse proxy setup using traefik. It's great!

I am trying to figure how to configure it such that when someone goes to HOSTNAME or www.HOSTNAME, that I can have it default route to some container/subdomain of my choosing. Assume valid DNS records.

I have a config toml file here. I then launch a bunch of containers, which the docker backend watches & picks up. For example,

static:
    image: myrepo/static
    volumes:
      - /www/static:/www/static
    depends_on:
      - traefik
    labels:
      - "traefik.backend=static"
      - "traefik.frontend.rule=Host:static.$HOSTNAME"

Browsing to static.HOSTNAME works right now. Yahoo! But suppose I want a browse to HOSTNAME to also serve static.HOSTNAME.

Any tips would be great! Thanks.

cdaringe
  • 1,274
  • 2
  • 15
  • 33

2 Answers2

4

A CSV of rules can be provided:

- "traefik.frontend.rule=Host:<subdomain>.$HOSTNAME,$HOSTNAME"
cdaringe
  • 1,274
  • 2
  • 15
  • 33
3

I used a regex rules (catchall in example here):

labels:
  - traefik.http.routers.customname.rule=HostRegexp(`{catchall:.*}`)

Traefik 2.0

SuperSandro2000
  • 581
  • 10
  • 20
fty4
  • 568
  • 9
  • 18
  • 1
    Are we sure that it will be used as a fallback if no other rule matches? I think the intention is that it matches only if "no other configured domain matches explicitly" – Xosofox Sep 22 '21 at 16:35