Caddy file server browse not working

Hi, I am a new baby here, something is really confuse me when I specify the root for file_server, for example

1. Caddy version (caddy version):

v2.5.1

2. How I run Caddy:

Caddyfile

example.com {
        handle /files/* {
                file_server browse {
                       root ./asset
                }
        }
}

my directory

ubuntu:~/code/caddy$ tree
.
├── asset
│   ├── name.wav
│   ├── start.sh
├── caddy
├── Caddyfile

a. System environment:

ubuntu

b. Command:

./caddy start

When I enter example.com/files, I expect I could get a file explorer page, but actually nothing. when I delete handle /files/* { and visit example.com, everything works fine

according to Caddy file server browse not working when root a specific directory,

	handle_path /files* {
		root * /asset
		file_server browse
	}

works, but the following snippet won’t work and I still don’t know why

	handle /files* {
		root * /asset
		file_server browse
	}

or

	file_server /files* browse {
			root * ./asset
	}

I try to visit example.com/files or example.com/files/asset, I get a blank page

You used a matcher of /files/* which does not match /files. You would need to use a /files* matcher instead to match that path.

The handle_path directive strips the given matcher from the request path before continuing. handle does not.

So for example with a request like /files/foo.txt, when file_server assembles the path, it looks for files at ./asset/files/foo.txt for example, instead of /asset/foo.txt, because /files doesn’t get removed by handle.

2 Likes

hi, thx for your reply!! it solve my problem!!

I change /files/* to /files* according to your advice

example.com {
	handle /files* {
		root * /asset
		file_server browse
	}
}

according to

because /files doesn’t get removed by handle .

so visit example.com/files actually visit ./asset/files directory (so I need to create files dir inside asset dir, it works, but it also means I can only visit file inside ./asset/files, there is no way to visit ./asset/foo.txt unless I change handle to handle_path )

visit example.com doesn’t get ./asset/ because it only handle files*

Yeah, essentially.

Is there a question hiding in there, or are you just recapping for yourself? Just making sure everything is clear

just recapping for myself, thx!

1 Like

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