Caddyfile - how to make dynamic domains?

Hi there.

It is necessary to implement that the root path be dynamic and be called up depending on the current domain

Like this:

    http://*.demo.local {
        tls off
        root /app/site/{label1}
        gzip
        log / stdout "{proto} Request: {method} {path} {label1}"
    }

But this is not work.
It is necessary that all requests to http://{domain}/demo.local go to root /app/site/{domain}
How can I do this?

Since wildcards and labels only cover one domain element, you’ll need to make one catch-all site for each length of FQDN you expect to handle.

Also, root doesn’t accept a placeholder. It looks like your folders are structured underneath the site root already, which is good. You’ll need to rewrite to append the folder name based off each domain.

Here’s an example:

(common) {
  root /app/site
  gzip
  log / stdout "{proto} Request: {method} {path} {label1}"
}

http://*.*.demo.local {
  import common
  rewrite {
    to /{label1}.{label2}{uri}
  }
}

http://*.demo.local {
  import common
  rewrite {
    to /{label1}{uri}
  }
}

Specifically, if you need this behaviour in particular:

Then you’d use something like this:

(common) {
  root /app/site
  gzip
  log / stdout "{proto} Request: {method} {path} {label1}"
}

http://*.*.*/demo.local {
  import common
  rewrite {
    to /{label1}.{label2}.{label3}{uri}
  }
}

http://*.*/demo.local {
  import common
  rewrite {
    to /{label1}.{label2}{uri}
  }
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.