Aliases and Multiple Domains

I read in another post about how to define an alias (aka apache/nginx) in Caddy. For example: {
    root /var/www/html
} {
    root /some/other/path

This seems straight forward…

But what if I serve many domains? I am not certain about the syntax. I currently have:

https:// {
	tls {

	encode zstd gzip

	root * /home/jimcook/mpa/custom/{host}
	php_fastcgi unix//run/php/php8.1-fpm.sock
	log {
		output file /home/jimcook/log/caddy.json
		format json

What I am trying to do is serve files, but if they have a specific path, /common7 in my case, serve those out of a different directory that is the same across all the domains.

So in the example above, I would want a site to serve files out of /home/jimcook/mpa/custom/ and that works, but if they specify

I want to get them to serve out of a different directory and I can’t figure out the proper syntax… it seems that using https:///common7 would be odd looking, but is that correct?

p.s. I am in the process of retiring my last apache2 server and replacing it with Caddy. Caddy rocks!

1 Like

You can replace

root * /home/jimcook/mpa/custom/{host}

with something like

root * /home/jimcook/mpa/custom/{host}
root /common7* /some/other/path

See the “Change the site root only for requests in /foo/*:” example at root (Caddyfile directive) — Caddy Documentation


THANK YOU! It never occurred to me that you could have more than one root directive. This will be perfect and completely understandable. THANK YOU!!!


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