How to create a router rule for a wildcard?

So you are not using the right syntax.


version: "3"

services:
  traefik:
    image: traefik:v3.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:ro

  whoami:
    image: traefik/whoami:v1.10.1
    labels:
      - traefik.enable=true
      - traefik.http.routers.whoami.rule=Host(`adguard.example.localhost`) || HostRegexp(`.+\.adguard\.example\.localhost`)
$ curl adguard.example.localhost    
Hostname: 09010fe37486
IP: 127.0.0.1
IP: 172.22.0.2
RemoteAddr: 172.22.0.3:43142
GET / HTTP/1.1
Host: adguard.example.localhost
User-Agent: curl/8.2.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.22.0.1
X-Forwarded-Host: adguard.example.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: e323edab02fd
X-Real-Ip: 172.22.0.1
$ curl foo.adguard.example.localhost
Hostname: 09010fe37486
IP: 127.0.0.1
IP: 172.22.0.2
RemoteAddr: 172.22.0.3:43142
GET / HTTP/1.1
Host: foo.adguard.example.localhost
User-Agent: curl/8.2.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.22.0.1
X-Forwarded-Host: foo.adguard.example.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: e323edab02fd
X-Real-Ip: 172.22.0.1
$ curl bar.adguard.example.localhost
Hostname: 09010fe37486
IP: 127.0.0.1
IP: 172.22.0.2
RemoteAddr: 172.22.0.3:43142
GET / HTTP/1.1
Host: bar.adguard.example.localhost
User-Agent: curl/8.2.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.22.0.1
X-Forwarded-Host: bar.adguard.example.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: e323edab02fd
X-Real-Ip: 172.22.0.1
1 Like