X-Accel-Redirect

Kiril Angov kupokomapa at gmail.com
Wed Sep 30 16:01:31 MSD 2009


X-Accel-Redirect is for sending files already in the hard drive,
rather than dinamically generated ones. The point is to do some logic
in a scripting language and to send a file to the user without them
knowing the real location on the server. Most of the time with:

location /protected {
  internal;
}

On Wed, Sep 30, 2009 at 1:07 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:
> Hello!
>
> On Wed, Sep 30, 2009 at 06:59:26PM +1000, Jeff Waugh wrote:
>
>> <quote who="pepejose">
>>
>> > -- In the first case X-Accel-Redirect not working because the image is in
>> > memory?  -- If I change the second case to:
>> >
>> > header("Content-type: image/jpeg"); header("X-Accel-Redirect: /$image");
>> > readfile($image);
>> >
>> > how can I know if the header X-Accel-Redirect is working?
>>
>> The X-Accel-Redirect header basically says:
>>
>>   Dear nginx (or some other frontend),
>>
>>   I know you're talking to me with fastcgi or http (proxy), but now I've
>>   figured out that I'm just going to be sending the client a file. You can
>>   do this better than me (by talking directly to the kernel and disk, and
>>   not sending the file over the fastcgi or proxy connection), so here's the
>>   name of the file.
>>
>>   Love,
>>
>>   Backend Application
>>
>>
>> So, what you want to do in your backend is this:
>>
>>   header("Content-type: image/jpeg");
>>   if ( X_ACCEL_DIRECT ) { // this shoudl configurable in a productised app
>>     header("X-Accel-Redirect: /$image");
>>     exit;
>>   }
>>   readfile($image); // send the image if we're not using X-Accel-Redirect
>>
>>
>> The initial path should probably be mildly more unique though, so you can
>> deal with it separately in your nginx configuration. But not necessarily.
>>
>> Short answer: X-Accel-Redirect is helpful only when the file is on disk.
>
> Not really.  It may as well mean "Dear nginx, I'm really sorry but
> I have no file in question available here.  But I'm sure it should
> be available from this URI (that will map to different backend),
> try it."
>
> But sending file contents along with X-Accel-Redirect header is of
> course meaningless.
>
> Maxim Dounin
>
>>
>> :-)
>>
>> - Jeff
>>
>> --
>> linux.conf.au 2010: Wellington, NZ                http://www.lca2010.org.nz/
>>
>>   "First-born children are less creative but more stable, while last-born
>>          are more promiscuous, says US research." - BBC News, 2005
>>
>
>





More information about the nginx mailing list