Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gate access to static files via backend #3347

Closed
toraora opened this issue May 4, 2020 · 8 comments
Closed

Gate access to static files via backend #3347

toraora opened this issue May 4, 2020 · 8 comments
Labels
feature ⚙️ New feature or request
Milestone

Comments

@toraora
Copy link

toraora commented May 4, 2020

This is basically X-Accel-Redirect in Nginx, and it used to exist as http.internal in Caddy 1, but I don't seem to be able to find a way to implement this behavior in Caddy 2

@mholt mholt added the feature ⚙️ New feature or request label May 4, 2020
@toraora
Copy link
Author

toraora commented Jun 4, 2020

I've written a plugin that I'm using for a toy site, but don't know enough about Caddy or its design principles to feel comfortable putting it up as a PR yet. If you can provide some feedback or guidance, I'd be happy to submit it, but for now I'll just put it here for other people to use:

https://gist.github.com/toraora/76016ef1fed9b551121ce41672c001bd

@francislavoie
Copy link
Member

Neat! You could take a look at some of the other Caddy v2 modules in this list to see how the organize their github repos as plugins: https://caddy.community/t/list-of-caddy-2-modules/7839

The one thing that I think is glaringly missing is Caddyfile support, which is pretty easy to implement. There's a doc here that explains the process: https://caddyserver.com/docs/extending-caddy/caddyfile

@mholt mholt added this to the 2.1 milestone Jun 4, 2020
@mholt
Copy link
Member

mholt commented Jun 4, 2020

Nice work @toraora ! But, this can be done using Caddy's built-in reverse proxy: 538ddb8#diff-3820b4f14e2fee163a1894dbf2560bd9R97-R109

It'll go out with 2.1 so it'll be documented on the website around that time.

Still needs Caddyfile support. But it should do the trick! And is way more flexible than working only with X-Accel-Redirect.

@mholt mholt closed this as completed Jun 4, 2020
@maxatome
Copy link
Contributor

Hi @mholt, do you have an ETA for the Caddyfile support? at least an issue we can follow?
Thanks!

@mholt
Copy link
Member

mholt commented Aug 31, 2020

I don't yet; feel free to submit a PR to expedite the change!

@maxatome
Copy link
Contributor

Do you have a spec of what you want to expose and how in Caddyfile? An example of final Caddyfile and what it should produce would be very appreciated before implementing anything :)

@mholt
Copy link
Member

mholt commented Aug 31, 2020

Sure, I can come up with something -- can you open a new issue to request that feature?

@mholt
Copy link
Member

mholt commented Aug 31, 2020

Maybe something like this:

reverse_proxy ... {
	...
	handle_response header X-Accel-Redirect {
		... 
	}
	handle_response status 4xx {
		...
	}
	handle_response {
		...
	}
}

(Responses can be matched by headers or status code. Just showing a few examples here.)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants