Jeff Waugh jdub at bethesignal.org
Wed Sep 30 12:59:26 MSD 2009

<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.


  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");
  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