I am trying to migrate from nginx and I need to use regular expressions in the hostname. Also, I am using a wildcard SSL certificate.
What is the recommended approach for this use case?
This is one example of the hostname regex ^(webview-|browser-|extensions-)?(?P<workspaceIDKey>[a-z0-9][0-9a-z\-]+).ws(?P<locationKey>-[a-z0-9]+)?.{$DOMAIN}
What I already tried:
I can write a middleware but would mean I will end up with one server definition like *.*.{$DOMAIN}.
I’m not sure how much of your regexp syntax is supported by Golang’s regexp engine, but you can play around on https://regex101.com/ to find out.
Are you bringing your own wildcard certificate to Caddy, or do you expect to use Caddy to automate it? Because Caddy can only issue single-level wildcard certificates. You could use On-Demand TLS though, if there’s not an inordinate amount of possible combinations of domains you want to allow.
@francislavoie thank you for the quick response.
That was exactly the first approach I took. My next issue with that is that I need to extract details from some regexp group. That’s where it starts to get messy .The middleware approach (Go) allows me to extract the fields and use an expression.
Are you bringing your own wildcard certificate to Caddy, or do you expect to use Caddy to automate
Yes, I am using a certificate generated with cert-manager (mounted as a volume). That works just fine.
For some context of what I am trying to do: I want to migrate from nginx in gitpod.io
And maybe this is just me but I tend to prefer to put the matchers right next to where they’re used, instead of all at the top. Reads more like code with this sort of structure:
condition1 = true
if condition1 {
return ...
}
condition2 = false
if condition2 {
return ...
}
return ...