Is it possible to use regex in the name of domains?

Hi!

I am using caddy 2 and i just wondering if possible to use regex in the name of domains, for instance, blog-*.example.com { import blog; }

so, blog-1 and blog-2 will be point to the same backend server.

No, it’s not possible. Caddy requires you to specify the exact name so it can manage certificates automatically. See the Automatic HTTPS docs:

If you want a wildcard certificate, Caddy can do that too (you must build Caddy with the appropriate DNS plugin and configure it so Caddy can solve the DNS challenge), but it must be in the form *.example.com, i.e. the * wildcard must be the only thing in that label (each section between the dots are called labels).

When using a wildcard site address, you can use a pattern like this to use the host matcher (or header_regexp matcher with the Host header if you have more complex patterns to match) to make routing decisions:

For next time, please fill out the help topic template, which appears when you open a topic on the Help category. (You chose the wrong category when opening the topic, I’ve moved it to the Help category).

1 Like

Thanks for taking look at this!

This topic was automatically closed after 29 days. New replies are no longer allowed.