X-Accel-Redirect testing

António P. P. Almeida appa at perusio.net
Tue Oct 2 12:19:33 UTC 2012

On 2 Out 2012 14h01 CEST, nginx-forum at nginx.us wrote:

> António P. P. Almeida Wrote:
> -------------------------------------------------------
>> XSendfile in Nginx is called X-Accel-Redirect.
>> The way X-Accel-Redirect works is that your app/backend sends a
>> "special" header with the location of the file that is to be served
>> by Nginx. Usually the application case is for speeding up the
>> delivery of protected/private files. Let's say you have a ecommerce
>> site that sells digital downloads. Then these files will be
>> protected and for speeding up the delivery your application sends
>> an X-Accel-Redirect header with the location of the file. Then the
>> file is delivered by Nginx as a regular static file.
>> Example: I request to download:
>> http://myshop.com/downloads/big_hit.flac
>> The file is stocked at /path/to/the/flac_files/big_hit.flac
>> your ecommerce sends an header:
>> X-Accel-Redirect: /path/to/the/flac_files/big_hit.flac
>> when Nginx sees this he knows that now the file is to be served
>> directly from the file system as a regular static file. Note that
>> the real location is hidden from the client.
>> Note that the real location must be protected from direct access by
>> the client always, be it from your app, be it from your server, for
>> example using the internal keyword:
>> http://nginx.org/en/docs/http/ngx_http_core_module.html#internal
>> In a nutshell that's how it works.
> I ended up using nginx as a reverse proxy, although this is what I
> wanted to avoid in the first place (bandwidth reasons).  Main
> traffic passes through nginx which forwards it to apache by
> proxy_pass, and apache sends back the X-Accel-Redirect and nginx
> responds with the file (protected with internal; ).

Instead of Apache you can make your app return that header. For
example, on drupal there's a module that sends that header for
protected file systems.

--- appa

> Posted at Nginx Forum:
> http://forum.nginx.org/read.php?2,231059,231311#msg-231311
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

More information about the nginx mailing list