I'm using traefik and docker to run multiple services on my server. How can I specify a default or fallback container, if there is no matching container for a (sub-)domain? For example, I'm using example.com for my website and cloud.example.com for my nextcloud. But when someone is using www.example.com or wiki.example (or one of the other possible subdomains) it shoud redirect to my website and not showing a 404 error page.
Each container has the following labels:
- traefik.port=<port>
- traefik.frontend.rule=Host:<sub-1>.example.com,<sub-2>.example.com
- traefik.frontend.entryPoints=http,https
The traefik configuration is here (I'm using the traefik:1.6-alpine image):
# General
logLevel = "INFO"
# EntryPoints
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
# Let's Encrypt
[acme]
entryPoint = "https"
email = "[email protected]"
storage = "/etc/traefik/acme/acme.json"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"
[[acme.domains]]
main = "example.com"
# Docker
[docker]
domain = "localhost"
watch = true
If you want all traffic but a few subdomains to go to your web container:
replace: traefik.frontend.rule=Host:<sub-1>.example.com,<sub-2>.example.com
with: traefik.frontend.rule=HostRegexp:{subdomain:[a-z0-9]+}.example.com, and add a priority label of 10: traefik.frontend.priority=10.
Then set a higher priority on any other services that you want to match before falling back to your website.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With