X-Accel-Redirect
Gabriel Ramuglia
gabe at vtunnel.com
Wed Sep 30 21:26:54 MSD 2009
Most of that is right, but, the file does not have to be on disk. If
you accel-redirect using an http:// link instead of a file path, that
will also work.
On Wed, Sep 30, 2009 at 1:59 AM, Jeff Waugh <jdub at bethesignal.org> 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.
>
> :-)
>
> - 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