FAQ

Page Discussion History

Difference between revisions of "XSendfile"

m (Adding link to standard format documentation.)
(dead link)
 
Line 61: Line 61:
 
[http://kovyrin.net/2010/07/24/nginx-fu-x-accel-redirect-remote/ Nginx-Fu: X-Accel-Redirect From Remote Servers]  from [http://kovyrin.net/ Alexey Kovyrin]
 
[http://kovyrin.net/2010/07/24/nginx-fu-x-accel-redirect-remote/ Nginx-Fu: X-Accel-Redirect From Remote Servers]  from [http://kovyrin.net/ Alexey Kovyrin]
  
[http://github.com/goncalossilva/X-Accel-Redirect Rails plugin for X-Accel-Redirect]
+
[http://guides.rubyonrails.org/asset_pipeline.html#x-sendfile-headers Rails 3.x assets pipeline support for X-Accel-Redirect]
  
 
[[NginxHttpProxyModule#proxy_ignore_headers| proxy_ignore_headers]] Ignoring Content Type headers when using X-Accel-Redirect
 
[[NginxHttpProxyModule#proxy_ignore_headers| proxy_ignore_headers]] Ignoring Content Type headers when using X-Accel-Redirect
  
 
[[NginxHttpProxyModule#proxy_hide_header| proxy_hide_header]] Hide headers from upstream servers when using X-Accel-Redirect
 
[[NginxHttpProxyModule#proxy_hide_header| proxy_hide_header]] Hide headers from upstream servers when using X-Accel-Redirect

Latest revision as of 14:13, 7 March 2013

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 /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/ {
  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