Page Discussion History


Revision as of 14:13, 7 March 2013 by ShiningRay (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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/ {
  root   /some/path;

If the application adds an header X-Accel-Redirect for the location /protected/iso.img:

  X-Accel-Redirect: /protected/iso.img;

then nginx will serve the file /some/path/protected/iso.img — 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/ {
  alias   /some/path/; # note the trailing slash

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


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