People used to alias (as in nginx and Apache) have often problems to realize how to achieve the same in Caddy, as these posts show:
- Missing equivalent to aliases, which contains the answer (use path and root).
- Trying to convert Taiga Nginx configuration, which contains another form of the answer (use subdomains and root).
- github issue/question 1851
I suggest to add an explanation in Caddy documentation. The important is adding the “alias” keyword, so it’s easy to find. Even if Caddy does not have the concept of “alias”, you might say something like: “Caddy can achieve what alias in other web servers do,…”. Possible places to add this:
- tutorial/caddyfile: after the subdomain you may add a
mysite.com/path/
(do say that trailing slash is important). - docs/http-caddyfile
- FAQ
I have some questions though.
In the post mentioned before @Whitestrake wrote that:
you’d need to duplicate across any directives from the main vhost that are also applicable to the more specific location, such as fastcgi directives, security rewrites, etc…
but I guess that not all the directives need to be duplicated. Here’s an example of my Caddyfile which I’m using to serve HTML files located outside the web server root:
:80 {
tls off
gzip
errors /var/log/caddy/errors.log
log /var/log/caddy/access.log
browse
root /var/www
}
:80/foo/ {
root /path/to/foo
}
I can see that at least tls and log directives, defined for :80
are effective also for :80/foo/
. I’m not sure about gzip and errors, but it may be valid for them as well.
On the other hand, browse is effective only for the main site and not for foo. So it’s a directive that should be duplicated.
Can you better explain how can we guess which directives must be replicated and which not?
Thanks in advance