Multiple different sub folders, rewrites?


Trying to bolt various different folders into several applications. Right now, I’m doing this and it’s cool, but seems cumbersome.

localhost:2000 {
  root ./encollab.dp.test.shared/webapp/

localhost:2000/resources {
  root ~/node/ui5/sapui5-rt-1.52.4/resources/

localhost:2000/resources/shared {
  root ./encollab.dp.shared/

Second, this is one application of many small ones. The /resources and /resources/shared bit is the same for all those applications IE; I will also have localhost:20xx with a different root but same resources, etcetera.

Is there a way to make those two paths reusable in other caddyfiles? Or alternatively, specify many ports at once somehow?


The simplest way without specifying different roots in different site definitions is to actually move those files on disk into a subdirectory of your main web root, i.e. mv ~/node/ui5/sapui5-rt-1.52.4/resources ./encollab.dp.test.shared/webapp/.

As for making the same web root available on multiple hosts or on different ports, you could add additional site labels:

localhost:2000/resources/shared, localhost:20xx/resources/shared {
  root ./encollab.dp.shared/

As for making the same configuration reusable in different Caddyfiles, you can separate any config into its own file and import them. Any import statement in a Caddyfile is treated as though the contents of the imported file were there instead.

1 Like

Alright cheers. Moving those shared resources is not an option (althought I could symlink them perhaps…?) but the comma separated syntax and imports will save me some redundant config.

There’s also the recently-added Caddyfile snippets, which are useful to reuse configuration in the same Caddyfile, just in case that’s also applicable:

I don’t have much experience symlinking in files, but at the very least if that has odd behaviour a hard link should definitely work.

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