Sendfile / X-Accel-redirect / v1's "Internal" directive

Hello - I hope you’ll excuse my non-use of the help template, but this is more of a general question.

I’d like to port this Caddyfile from v1 to v2, but haven’t found an equivalent to the http.internal directive that it uses:

{%HTTP_HOST%}
tls ttrss@{%HTTP_HOST%}
root /var/www/html
log stdout
errors stderr
internal /tt-rss/cache
fastcgi / app:9000 php

With the introduction of reverse_proxy’s “handle_response” function in v2.1, is it now possible to have Caddy 2.1.x look for an “X-Accel-Redirect” header in order to allow selectively bypassing a PHP fastcgi router and serving a static resource directly from a cache folder instead?

This is used by TT-RSS, a popular ttrss reader that is bundling caddy (currently, caddy v1) as part of a docker-compose bundle; the lead dev is insisting we hold off on a switch to v2 until there’s X-Accel-Redirect / sendfile support. Apparently something like try_files won’t do: Docker-compose + tt-rss - #220 by 6v4FVnZm - Development - Tiny Tiny RSS: Community

Mholt’s comment here suggests it should be doable, but I’m afraid I’m too much of a newb to figure this one out. I think there are enough people migrating over from nginx that they’d welcome an example of how to use this new feature specifically with X-Accel-Redirect headers!

Unfortunately it’s not a feature that’s available in the Caddyfile yet. You’ll need to adapt your config to JSON then make some modifications to get this to work. You’ll use the caddy adapt command for this.

It’s part of the reverse_proxy handler (which php_fastcgi is a shortcut for). See the JSON docs for reverse_proxy, and the handle_response part of it.

The idea is you would use a header matcher to see if there’s an X-Accel-Redirect header set, in which case it would get handled with a rewrite (taking the header value as your path) followed by a file_server with the root set to actually serve the file. You might also want to turn on content encoding in there as well for compression.

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