Debian 10. Systemd template. caddy user created from wiki.
I am trying to switch from nginx over to Caddy but have been running into some trouble. I’m using a Caddyfile (more familiar than json formatting) but haven’t been able to understand how to use the handles correctly to mimic the location blocks in nginx.
I have a few folders and symlinks that I’d like to have caddy serve (with different credentials for each handle).
My nginx config looks like this
I have more location blocks that are in my original nginx config but they are similar to the above.
My attempts at getting this mimicked (at least the permalink serving for the file server) have all failed. I’ve tried handle /39bm2k-name/* as well with no luck.
With that admin gets access to everything. user1 and user2 can only access their folders with their given passwords.
That sets the root path and then basicauth /user/* sets the path with that requires a username password login. I don’t know about some of those autoindex things you have in there but Caddy will configure directory listings without and index file if using the browse.
Oh thank you. This is very close to what I’m trying to do. In nginx, it’s a bit different.
Nginx’s locations are like permalinks, so I have https://domain.name.com/39bm2k-name actually list the directory of /usr/share/nginx/html/folder/name. I was thinking using handles would allow for it to work but it hasn’t for me. Maybe rewriting urls? Not sure.
I have the added characters in the beginning to make the permalink harder to guess but the folders are simplified on disk. Actually they are just symlinks that point to an rclone mount.
I’m wondering if maybe it could be possible to emulate them in Caddy. for example I have /usr/share/nginx/html/folder/name which is a normal folder but inside that are two symlinks that point to rclonefolder1inmountrclonefolder2inmount. Could it be possible to add blocks for /39bm2k-name/name and /39bm2k-name/name2 and not have to use symlinks? Or maybe if rclone has a module for caddy, not sure
In the web address bar if I put mydomain.duckdns.org/user1 it actually takes me to mydomain.duckdns.org/users/user1 and same for user2.
Unfortunately for me I can’t get the user2 to prompt me for a password. user1 seems to work just fine though. If that’s what you’re looking for then I hope this gets you moving in the right direction. Don’t worry about the hash-passwords I left in the file. This was just for testing.
All the handle and route blocks there are unnecessary frankly. You could have just the one file_server directive outside of route/handle and all of the redirects outside as well and it should do the same thing.
And I don’t think the root along with redirects will have the desired effect. Request paths in Caddy are appended to the root, so you’ll be making requests for:
I’ll be honest, I’m a bit confused as to what is trying to be achieved here. Could you give a few example requests (like GET /some/path) and explain for each of them what the desired effect is? Try to be as thorough as possible with what you expect to happen. That should make it easier to help you write a config to achieve that goal.
Nginx’s locations are like permalinks, so I have https://domain.name.com/39bm2k-name actually list the directory of /usr/share/nginx/html/folder/name .
I tried doing the file_server and redirs outside of both handle and route to no avail:
With that config though user2 loads to it’s page without a password prompt and user 1 gets a 404. I tried many variations to it also.
I also understand what you’re saying about the root and it makes total sense, however for some reason it wouldn’t work if I used
/srv/dev-disk-by-label-HomeDrive
or /srv/dev-disk-by-label-HomeDrive/users
The only way I could get it to work was by putting that full path in the config you’re referring to. I’m sure it’s an issue on my part with the way Caddy does its exact path matching.
I was hoping the nginx config could help explain the situation. I’m thinking that maybe Caddy might not be able to do what nginx is currently. I might just switch back to nginx.
Is it possible to hide folders after the root directive? I want to allow access to two folders out of a dozen with webdav support. I think putting each user was on a subdomain might be better than using handles.
I was hoping to have user1.domain.com/ show only the two directories using file_server and also in the webdav module too. I couldn’t find a way to hide outside of file_server's hide.
Oh, derp, my bad. I forgot to add the strip_prefix part to that config above. Sorry about that.
redir /39bm2k-name /39bm2k-name/
handle /39bm2k-name/* {
uri strip_prefix /39bm2k-name
root * /usr/share/nginx/html/folder/name
basicauth {
Bob <pass>
}
}
Nginx implicitly strips the prefix when using location blocks, but not Caddy. If you use Caddy v2.1 beta 1 though, there’s now the handle_path directive which has that same behaviour (same as handle + uri strip_prefix, saves a line).
Yes - there’s the hide option for the file_server directive that lets you specify filenames to exclude from the browse pages. You can also use a path matcher with a respond directive to return a 404 error when requested.