-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Support for nginx style X-Accel headers in reverse_proxy #3828
Comments
I recently encountered a bad interaction between Nginx is always such a pain in the ass... |
Caddy's JSON config is capable of supporting very nuanced routes and handling logic, so I wouldn't worry about that. The functionality, if it does not already exist, just needs to be implemented. This is a pretty vague description of everything though, and there seems to be a lot to unpack. Frankly, I'm not really sure what you're getting at. I think this is a feature request? Can you be more specific please? |
Yes, indeed.
NGINX's I'm using Rack specificsIn Ruby/Rack applications (like Rails), I can configure which kind of header the application should use. The default config for production contains these lines: Rails.application.configure do
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
end The nitty-gritty details can be found in Use casesThere are two reasons why this is useful:
There might be more, but I believe this are the main reasons. Protocol overviewThe protocol (on the application side) is quite simple: The application just finishes a response without a body: HTTP/1.1 200 OK
X-Sendfile: /path/to/some/file.ext That HTTP response from the proxied application is intercepted by the web server, and rewritten to something like this, if an HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="file.ext"
Content-Length: 1234567
1234567 bytes omitted Some header fields are filled in when not provided by the application (IIRC, Content-Type, -Length and -Disposition), others are removed (X-Sendfile obviously), and the rest is copied without changes. CaveatsAs described above, the Example deploymentGiven a example.com {
root * /srv/app/public
# copied from one of our production systems;
# not sure if minimal enough - I've cut large parts
@notStatic {
not {
file {
try_files {path}
}
}
not {
path /assets/*
}
}
reverse_proxy @notStatic http://127.0.0.1:3000
file_server
} and a file structure like
a request to However, the application server might set |
From what you've described, I believe you can already accomplish this with
If I were you, I'd just match on the expected status code and header, then chain together whatever handlers you need to finish handling the request. |
Cool, I'll have a look later. From a first glance, this isn't available from a Caddyfile, only by in the JSON config tree, correct? |
Following along, I would love to use this together with my php-fpm upstream, and redirect the file download to s3proxy when applicable 🤔 |
@Richard87 you'll be able to do this with #4021 (or build with that now to play with it). The functionality to do this already exists in Caddy via JSON config, this just adds Caddyfile support. |
#4021 has been merged. |
Nginx has support for an upstream server to effect it by setting
X-Accel-*
headers in the response (NGINX | X-Accel).This feature is very useful for various different scenarios, for example:
X-Accel-Buffering
).internal
/named location only accessible ro such internal redirects (X-Accel-Redirect
).internal
/named location, only accessible by such internal redirects (X-Accel-Redirect
).Some of this behavior is probably possible by
handle_response
, which is not currently available in the Caddyfile (#3707), and even if it would be available, a stock handler/config snippet for this behavior would still be useful.Note that there are some fine details with how nginx behaves with those headers, for example: It changes the request method to a
GET
unless you redirect to a named location when usingX-Accel-Redirect
. Both changing the method (e.g. APOST
that redirects to a static file), and not changing it (e.g. Offload to a different proxied server) are useful and need consideration how to make them available in caddy.It also doesn't seem like Caddy has such named locations or internal locations/matcher to create such internal redirect only routes.
Also another interesting custom header of this sort is
X-Sendfile
supported by Apache.The text was updated successfully, but these errors were encountered: