Caddy 2, file server using route (caddy.json

I’m using this config.json

{
“apps”: {
“http”: {
“servers”: {
“example”: {
“listen”: [
“127.0.0.1:3000”
],
“routes”: [
{
“match”: [
{
“path”: [
“/”
]
}
],
“handle”: [
{
“browse”: {},
“handler”: “file_server”,
“root”: “./static”
}
]
}
]
}
}
}
}
}

And when I open localhost:3000, file browser appears, I want to open the file browser only when I go to localhost:3000/static, so I change the
“path”: [
“/”
]

to
“path”: [
“/static”
]

And the result is

  • localhost:3000 → blank page
  • localhost:3000/static → This localhost page can’t be found

How to co configure the route ?

Thanks

Path is just a matcher, with the path /static and a root of ./static, Caddy will look in ./static/static, which probably doesn’t exist.

Use root . and match path /static.

I’d also advise using absolute paths rather than relative. The latter can seriously confuse things occasionally.

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