# X-Accel-Redirect testing

**URL:** <https://www.ruby-forum.com/t/x-accel-redirect-testing/223207>\
**Category:** NGINX\
**Created:** [September 26, 2012, 12:28am UTC](https://www.ruby-forum.com/t/x-accel-redirect-testing/223207 "2012-09-26T00:28:33Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![w00t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/e19b73/32.png) [@w00t](https://www.ruby-forum.com/u/w00t)\
**Post date:** [September 26, 2012, 11:04am UTC](https://www.ruby-forum.com/t/x-accel-redirect-testing/223207/4 "2012-09-26T11:04:12Z")

</div>

On 26 Set 2012 10h17 CEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for the reply. I’d love to at least understand the basics, in  
> fact this is what I’m trying to do. It’s a bit hard when there’s no  
> thorough documentation and all responses found on internet are  
> vague.
> 
> You are saying that it will work only when Nginx is a reverse proxy  
> and receives a response from another backend, like Apache. But I  
> want Apache as frontend and Nginx as backend. Should I focus on  
> Xsendfile?

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:

> **[404 | Oops deze pagina bestaat niet! Bekijk myshop.com | myShop.com](http://myshop.com/downloads/big_hit.flac)**
>
> 404 | Oops deze pagina bestaat niet! Bekijk myshop.com | myShop.com

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:

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#internal)**
>
> This directive appeared in version 1.11.8.

In a nutshell that’s how it works.

HTH,  
— appa

---

_[View the full topic](https://www.ruby-forum.com/t/x-accel-redirect-testing/223207)._
