File server only at a specific URL path

1. Caddy version (caddy version):


2. How I run Caddy:

caddy run with a Caddyfile in the pwd (/home/hari/public)

a. System environment:

vanilla centos 7

d. My complete Caddyfile or JSON config: {
    file_server /files {
        root /home/hari/public
    log {
        output file /opt/logs/caddy.log
}” resolves to the correct IP of the machine. I am not being a load balancer or some AWS internal VPC or whatever where the external IP of the machine doesn’t match the address of ifconfg or ip a

3. The problem I’m having:

I want to be able to go to and be shown the file server. I want to be able to go to and be reverse proxied to something (we will get to that later)

I have tried different combinations, but I either get a blank screen or a 404

5. What I already tried:

I have tried starting my block with, but that didn’t work either. I tried putting the root directive with a /files matcher outside, didn’t work. I tried putting root . inside the file_server, (apparently, inside the file server there is no matcher?) that doesn’t work either.

I even tried this, seperately I ran this
caddy file-server --listen --browse

and then had this in my config file {
reverse_proxy /files

but I am still seeing only blank pages

Finally, I tried the following 2 commands

caddy file-server --listen --browse
caddy reverse-proxy --from --to

And I see this
reverse-proxy: paths are not allowed:

TL;DR … I want to go to a file handler pointing to some path (/home/hari/public), and I want<some_service> to go to some other service

Thoughts? am I missing something basic here?

Hi Hari –

The docs say:

Path matching is an exact match by default; you must append a * for a fast prefix match. Note that /foo* will match /foo and /foo/ as well as /foobar ; you might actually want /foo/* instead.

See if that helps you solve the problem. :slight_smile:

Hi Matt

Thanks for the super prompt responses.
Where are you suggesting I add that?

Here’s what I have tried

caddy file-server --listen --browse on one terminal {
 reverse_proxy /files/*

but that does’t seem to get anything.

If I go to (with the trailing slash), it gives me 404.
If I go to (without) , it gives me a blank page and not the file browser UI. The other caddy listening on shows no log either

This indicates to me that the file server is probably working on the other Caddy but there’s no index file in the directory you started it in. That said, it probably should be showing you a browse UI here…

Because without a trailing slash, it doesn’t get proxied. If it doesn’t get proxied, there’s no other terminating handlers in your site to tell Caddy what content it should return. So it falls back on Status 200 (good request) with no content (Caddy has nothing to give you). This is the expected behaviour.

I’m a fan of this particular little Caddyfile pattern:

rewrite /files /files/
reverse_proxy /files/*

This essentially means "reverse proxy from /files and /files/ and /files/foo but not /filesfoo". It’s a bit more optimal than just reverse_proxy /files*, which will proxy from /filesfoo, which usually isn’t desirable behaviour.

1 Like

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