Would like to use Caddyfile with a wildcard DNS entry.
[edit: in the below nginx.conf, I was able to capture the subdomain value (server_name ~^([a-zA-Z0-9\-]+).+$ ;) and use it when setting the context root path (root /www/$1)]
a. System environment:
N/A
b. Command:
N/A
d. My complete Caddyfile or JSON config:
N/A
3. The problem I’m having:
Is there an easy way of doing something similar with Caddy as the following nginx.conf?
server {
listen 80;
server_name ~^([a-zA-Z0-9\-]+).+$ ;
root /www/$1;
}
Thank you!
Apologies, I was not able to articulate my question properly (or I just don’t understand your example).
I would like to catch the actual subdomain and use it later on.
So in the example from the site, in the fallback handler, if the server gets called from whatever12.example.com , I would like to serve the content from /www/whatever12 –
*.example.com {
# Fallback for otherwise unhandled domains
handle {
## would like to catch the actual value of '*' somehow
file_server
root * /www/<the-actual-subdomain>/
}
}
In the nginx.conf, I’m able to capture the value with a regexp group, and reuse it later:
Either you can use label placeholders to pull out the n-th segment of the hostname, or you can use a header_regexp Host matcher to pull out the value with a regexp capture group.