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.
in short, how can I verify that X-Accel-Redirect is working?
I looked at the headers with the plugin for firefox live http headers but
I see no differences
Add a header to an exclusive chunk of your PHP code or nginx
configuration.
For example:
if ( X_ACCEL_REDIRECT ) {
header(“X-Accel-Redirect: /$image”); // nginx will strip this
header(“X-For-The-Win: win”); // nginx won’t strip this though
exit;
}
readfile($image); // won’t ever have the X-For-The-Win header
You could also do something on the nginx side, but this lets you know
that
your app is at least doing the right thing.
If you’re proxy_pass-ing to the app, you can also just use curl or wget
to
talk to it directly, to see which headers it’s passing to nginx.
(Note that you can configure nginx to do anything based on the URL it
gets
from the backend -> you could proxy_pass again, fastcgi_pass, whatever.
But
it is most useful when you tell nginx to just serve up a static file.)
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:
On Wed, Sep 30, 2009 at 06:59:26PM +1000, Jeff W. wrote:
The X-Accel-Redirect header basically says:
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.
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.