Combining browse/proxy in same site directive

When visiting the following directive I always go to the proxy. Even when visiting https://fileserver.mysite.com/complete. How do I get the precedence working? I thought it was “most specific wins” and /complete should be the most specific.

https://fileserver.mysite.com {
	root /data/Downloads
	browse /complete

	proxy / http://my-firewalled-service:3000 {
		transparent
	}
}

As reference for my working config on nginx:

server {
    listen       80;
    server_name  fileserver.mysite.com;

    location / {
        proxy_pass http://my-firewalled-service:3000;
    }

    location /complete {
        alias /data/complete;
        autoindex on;
    }
}

I can see why this is a little confusing; first, directives have a specific order, and then after that, the directive may choose how to order the rules based on path (some don’t and just use the order they’re given in, others like proxy do a length comparison).

As for directives, proxy actually has precedence over browse.

What you have going on is more like two separate sites, in a sense.

You could try this:

fileserver.mysite.com/complete {
	root /data/Downloads/complete
	browse
}

fileserver.mysite.com {
	proxy / http://my-firewalled-service:3000 {
		transparent
	}
}

OK, great. That worked just fine. Interesting combination of features. Thanks!

1 Like

I’m gonna be honest, nginx’s config format is better structured for this type of thing. It allows you to do things that frankly the Caddyfile syntax doesn’t (or without a lot of repetition). But the Caddy way of thinking about sites is just a little different, and it ends up being simpler most of the time for most people once you get used to it. :slight_smile:

1 Like

One trick with this solution: the trailing slash on the request URL matters. I can request the browse directive with or without a trailing slash and it changes the generated pages.

good result - click around as expected and things are cool:
site url: https://fileserver.mysite.com/complete/
generated link: https://fileserver.mysite.com/complete/a-cool-folder/

bad result - links goes to a 404 error:
site url: https://candyhole.tureus.com/complete
generated link: https://fileserver.mysite.com/a-cool-folder/

Any tips on how to work around this?

@matt any thoughts on this?

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