Http.browse returns 404 when specifying folder and template

(no name) #1

Hi, I’m trying to serve a folder and its content via the browse plugin. I’m on Windows 10 and using Powershell to launch the Caddy executable. Browse works fine without specifying the directory to browse and the template to use, if i add them Caddy just returns 404 but without logging anything.
Complete Caddyfile:

localhost:2015
tls off
browse files neo.tpl

I suspect there’s something wrong with the relative location of the files but can’t fix it. Absolute paths (quoted and unquoted) also don’t work.

(Matthew Fay) #2

Do you have a /files subfolder in your webroot, and is there a neo.tpl in your CWD?

Can you post the output of curl -IL localhost:2015/files?

(no name) #3

This is the content of the folder:
image
And this is the output of the curl command:

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: /files/
Server: Caddy
Date: Tue, 14 May 2019 08:12:17 GMT

HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Server: Caddy
X-Content-Type-Options: nosniff
Date: Tue, 14 May 2019 08:12:17 GMT
Content-Length: 14

Thanks in advance.

EDIT: I also tried with the directive browse files and it also doesn’t work, so it’s not a problem of the template because even the default doesn’t load.

(no name) #4

So i got it to work by modifying the Caddyfile into:

localhost:2015
tls off
browse /files neo.tpl

What a difference a slash makes!

Turns out though that this was not the configuration i wanted, as i’d like to have the browseable folder as the root of the website (for aesthetic and obscurity reasons).
So i got another working Caddyfile:

localhost:2015
tls off
root files
browse / neo.tpl

The problem now is my template cannot load files up in the hierarchy (such as files in the css folder)! Can i do anything about it? Sorry if this question is OT

(Matthew Fay) #5

Good question - it’s a bit of a “have your cake and eat it too” problem.

You want to have the webroot correspond to files/, for aesthetic/security reasons, but you want to be able to navigate back up out of the webroot (such as to get stuff from the css/ folder), which is not permitted (for security reasons).

If you want files to be accessible, they must be inside your web root.

1 Like
(no name) #6

Ok then, I guess that’s reasonable enough. Thanks for your help!