Serve from multiple folders

Hi,

I’m currently migrating my services from nginx to caddy. I have one particular service where I have to serve the data from multiple folders. In nginx syntax this looks like:

location / {
root /var/www/mysite/public;
index index.html;
}

location /static/ {
root /var/www/mysite/static/;
}

location /downloads/ {
root /home/myuser/legacy/downloads/;
}

Is there a way to achieve this with caddy? I read through some github issues, but all of them were not really conclusive. In case it is not possible, is there a work around?

Thanks!
Tobias

Hi Tobias

You can create a site for each location

example.com {
   root /var/www/mysite/
   other directives.....
}

 example.com/static {
   root /var/www/mysite/static
   other directives.....
}

example.com/downloads {
   root /var/www/mysite/downloads
   browse
   other directives.....
}

Each one will work as a seperate site.

2 Likes

Caddy has an elegant solution to this:

example.com {
    root /var/www/mysite/public
}
example.com/static/ {
    root /var/www/mysite/static
}
example.com/downloads/ {
    root /home/myuser/legacy/downloads
}
1 Like

thanks @tobya and @matt

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