Traefik | More than 10 domains in a rule | Easier way needed?

The normal way for a site is to define the hostnames like this.

- "traefik.http.routers.nginx.rule=Host(``, ``)"

I have a project with about 10+ domains pointed to the service.... both with and without www. ... the configuration line will be larger and larger.

Is there an easier way to add all domains? Like a text file which can be used for both rules SSL and non-SSL, too?

Hello @mf1,

I don't have a real solution for you, but you could try using the HostRegexp matcher, matching (www.)? This way would allow defining a single host for both, thus cutting in half the definition size.

Hi @tommoulard .

Your idea looks great and perfect for this project. In this scenario it could safe more than 50% of definitions....

Mainly there is one domain with different syntax's. In my example with optional plural "s", optional hyphen "-", optional "www." and of course different TLDs.

- "traefik.http.routers.nginx.rule=HostRegexp(`(www.)?dom(-)?ain(s)?.(tld1|tld2|tld3|tld4)`)"

I've tried the optional www version, too. But this isn't working. Do I need to install more something more?

I don't see any issues with your regexp : regex101: build, test, and debug regex
You can use this tool to engineer a regexp that suits your needs :smile:

I always get 404 page not found from Traefik proxy. Even I used the smallest rule
- "traefik.http.routers.nginx.rule=HostRegexp(`(www.)?`)"

Using ...
- "traefik.http.routers.nginx.rule=Host(``, ``)"
... everything is working fine.

Using the more complex rule I get additional SSL issue because the LetsEncrypt certificate wasn't pulled, I guess.

It's really enough to just replace Host by HostRegexp parameter? No additional flag is needed?

It's because you are not using the correct format to define regexps in the HostRegexp matcher.
You could have done this:

      traefik.http.routers.nginx.rule: HostRegexp(`{wordwideweb:(www\.)?}`)

See Regexp Syntax on Traefik Routers Documentation - Traefik

Thanks. I've switched all the labels from "hyphen & quotes & equal" to "nothing & colon"
Now it's working with the standard rule. www and non-www.

I also use curly bracket for each rule which is now also named

traefik.http.routers.nginx.rule: HostRegexp(`{worldwideweb:(www\.)?}dom{hyphen:(-)?}ain{plural:(s)?}.{tld:(tld1|tld2|tld3|tld3)}`)

Using the more complex rule the normal domain is working, also with SSL. All other domains showing ERR_SSL_PROTOCOL_ERROR. How can I solve this?

Additional: Is it needed to have unique Match names overall projects running this Traefik instance?

I've found the reason why this isn't working. LetsEncrypt isn't usable with HostRegexp. In this case I have to put all domains separately ... this is what I actually wanted to make easier... :smiley: