X-Accel-Redirect, proxy_pass and Range Requests.
mdounin at mdounin.ru
Wed Oct 6 20:02:28 MSD 2010
On Wed, Oct 06, 2010 at 11:30:44AM -0400, Ben Timby wrote:
> I have some complex interaction going on here and I would like to see
> if anybody has some suggestions for me.
> I have Nginx in front of apache serving static files, performing
> compression and SSL. For large files, I use X-Accel-Redirect header to
> offload the sending to nginx. This all works beautifully.
> However, the problem is that the backend tracks downloads, it only
> allows a certain number of downloads per file. Some of these files are
> PDFs that are opened on the client side using Acrobat Reader. Acrobat
> Reader sends Range requests to nginx.
> Nginx will then forward the range request to apache, which returns a
> 200 including the X-Accel-Redirect header. Nginx then pulls the
> correct range from the indicated file and returns that to the client
> with a 206 status.
> The problem is, each of these range requests is counted by my backend
> as a download, expiring the download counter prematurely.
Even normal request may easily fail somewhere in the middle, and
even if nginx thinks it sent full response to client. Counting
downloads is just unreliable.
> My thought on a possible solution is to simply turn on caching in
> nginx, allowing it to satisfy subsequent range requests without
> hitting the backend. Something like the following:
> proxy_cache "zone_name";
> proxy_cache_key "$host$request_uri$cookie_sessionid";
> proxy_cache_valid 206 1m;
> However, I am curious if the proxy_cache_valid directive matches on
> the response code of the backend, or the response code that nginx will
> send to the client. Also, how does proxy_cache interact with
X-Accel-Redirect responses aren't cached.
More information about the nginx