XSendfile

This feature is documented in standard format here: http://wiki.nginx.org/X-accel

The delivery of a static file which depends on an application header is known as the X-Sendfile feature.

Lighttpd has this feature and there is a mod_xsendfile for Apache2.

Nginx also has this feature, but implemented a little bit differently. In Nginx this feature is called X-Accel-Redirect.

There are two main differences:


 * 1)  The header must contain a URI.
 * 2)  The location should be defined as internal; to prevent the client from going directly to the URI.

Example nginx configuration:

location /protected/ { internal; root  /some/path; } If the application adds an header X-Accel-Redirect for the location :

X-Accel-Redirect: /protected/iso.img; then nginx will serve the file /some/path/protected/iso.img &mdash; note that the root and internal redirect paths are concatenated.

If you want to deliver /some/path/iso.img then configure nginx like this:

location /protected/ { internal; alias  /some/path/; # note the trailing slash }

Note that the following HTTP headers aren't modified by nginx:

Content-Type Content-Disposition Accept-Ranges Set-Cookie Cache-Control Expires If some of these header lines are not set, then they will be set by the redirected response.

The application can also have some control over the process, sending the following headers prior to X-Accel-Redirect. X-Accel-Limit-Rate: 1024 X-Accel-Buffering: yes|no X-Accel-Charset: utf-8

Links to this issue
Using X-Accel-Redirect Header With Nginx to Implement Controlled Downloads (with rails and php examples) from Alexey Kovyrin

Nginx-Fu: X-Accel-Redirect From Remote Servers from Alexey Kovyrin

Rails 3.x assets pipeline support for X-Accel-Redirect

proxy_ignore_headers Ignoring Content Type headers when using X-Accel-Redirect

proxy_hide_header Hide headers from upstream servers when using X-Accel-Redirect