xd003
September 17, 2023, 11:56am
1
i want to reverse proxy a wildcard subdomain along the subdomain itself for the very same docker container. i have the following in the labels section of that container -
- "traefik.enable=true"
- "traefik.http.routers.container.rule=Host(`adguard.example.com`) || HostRegexp(`{subdomain:[a-z]+}.adguard.example.com`)"
- "traefik.http.services.container.loadbalancer.server.port=80"
adguard.example.com
seems be working well but i get 404 page not found
error on wildcard - *.adguard.example.com
. Any clue on what i must be missing here
The doc states this format
HostRegexp(`example.com`, `{subdomain:[a-z]+}.example.com`, ...)
There is also another (currently open) question about HostRegexp , so it seems to be not an easy topic.
xd003
September 17, 2023, 2:35pm
3
Even with this, only adguard.example.com
is working, *.adguard.example.com
still gives 404 page not found
- "traefik.http.routers.container.rule=Host(`adguard.example.com`) || HostRegexp(`{subdomain:[a-z]+}.adguard.example.com`)"
ldez
September 17, 2023, 2:47pm
4
version: "3"
services:
traefik:
image: traefik:v2.10
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(`{subdomain:[a-z]+}.adguard.example.localhost`)
$ curl adguard.example.localhost
Hostname: 350b021f5a2d
IP: 127.0.0.1
IP: 172.21.0.2
RemoteAddr: 172.21.0.3:35146
GET / HTTP/1.1
Host: adguard.example.localhost
User-Agent: curl/8.2.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.21.0.1
X-Forwarded-Host: adguard.example.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: cddcb1945fb1
X-Real-Ip: 172.21.0.1
$ curl foo.adguard.example.localhost
Hostname: 350b021f5a2d
IP: 127.0.0.1
IP: 172.21.0.2
RemoteAddr: 172.21.0.3:35146
GET / HTTP/1.1
Host: foo.adguard.example.localhost
User-Agent: curl/8.2.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.21.0.1
X-Forwarded-Host: foo.adguard.example.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: cddcb1945fb1
X-Real-Ip: 172.21.0.1
$ curl bar.adguard.example.localhost
Hostname: 350b021f5a2d
IP: 127.0.0.1
IP: 172.21.0.2
RemoteAddr: 172.21.0.3:35146
GET / HTTP/1.1
Host: bar.adguard.example.localhost
User-Agent: curl/8.2.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.21.0.1
X-Forwarded-Host: bar.adguard.example.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: cddcb1945fb1
X-Real-Ip: 172.21.0.1
Everything works as expected, your problem is not related to the rule.
@xd003 please don't edit your posts.
ldez
September 17, 2023, 2:53pm
5
Are you using Traefik v3?
Traefik v3 is in beta state and you are posting in the Traefik v2 category.
xd003
September 17, 2023, 2:54pm
6
Yes i am using traefik v3, my bad, had missed that one, edited to reflect the same
ldez
September 17, 2023, 2:55pm
7
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
system
Closed
September 20, 2023, 2:55pm
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.