X-Sendfile <=> X-Accel-Redirect header

Igor Sysoev is at rambler-co.ru
Sat Sep 2 19:35:17 MSD 2006

On Sat, 2 Sep 2006, Aleksandar Lazic wrote:

> is behind yours X-Accel-Redirect the same idea as in X-Sendfile?!
> http://celebnamer.celebworld.ws/stuff/mod_xsendfile/
> ---
> .
> .
> If it encounters the presence of such header it will discard all output
> and send the file specified by that header instead using Apache
> internals including all optimizations like caching-headers and sendfile
> or mmap if configured.
> .
> .
> ---
> If so is it possible to add X-Sendfile to
> 'ngx_http_upstream_headers_in[]' in src/http/ngx_http_upstream.c ;-)

The "X-Accel-Redirect" header line is similar to the "X-Sendfile", but
has two differences:

1) in XAR you should set an URI, but not path. The URI must be mapped
    in nginx configuration to some location. The "internal" directive
    should be used to protect the location from direct access:

    location /protected/ {
        root   /some/path;

    As XAR does internal redirect, the request can be redirected
    to another proxied or FastCGI server. It is not limited to static
    files only.

2) Some header lines from original response (with XAR) are inherited
    by an redirected response:


    If some of these header lines are not set, then they will be set
    by a redirected response.

> BTW: I haven't seen a doc for this, have I overseen it?!

It is still undocumented but well-known and used by Russian users.

Igor Sysoev

More information about the nginx mailing list