Byte-range request not possible for proxy_cache if origin doesn't return accept-ranges header
Roman Arutyunyan
arut at nginx.com
Thu Nov 15 09:29:59 UTC 2018
Hi Lucas,
On Wed, Nov 14, 2018 at 06:50:23PM +0000, Lucas Rolff wrote:
> Hi Roman,
>
> I can confirm that indeed does fix the problem, thanks!
>
> I do wonder though, why not let nginx make the decision instead of relying on what the origin sends or does not send?
nginx tries to be transparent and do not introduce any changes in the response
and behavior of the origin unless explicitly requested.
> Thanks!
>
> On 14/11/2018, 17.36, "nginx on behalf of Roman Arutyunyan" <nginx-bounces at nginx.org on behalf of arut at nginx.com> wrote:
>
> Hi,
>
> On Wed, Nov 14, 2018 at 02:36:10PM +0000, Lucas Rolff wrote:
> > Hi guys,
> >
> > I've been investigating why byte-range requests didn't work for files that are cached in nginx with proxy_cache, I'd simply do something like:
> >
> > $ curl -r 0-1023 https://cdn.domain.com/mymovie.mp4
> >
> > What would happen was that the full length of a file would be returned, despite being in the cache already (I know that the initial request, you can't seek into a file).
> >
> > Now, after investigation, I compared it with another file that I knew worked fine, I looked in the file on disk, the only difference between the two files, was the fact that one cached file contained Accept-Ranges: bytes, and another didn't have it.
> >
> > Investigating this, I tried to add the header Accept-Ranges: bytes on an origin server, and everything started to work from nginx as well.
> >
> > Now, I understand that Accept-Ranges: bytes should be sent whenever a server supports byte-range requests.
> > I'd expect that after nginx has fetched the full file, that it would be perfectly capable of doing byte-range requests itself, but it seems like it's not a possibility.
> >
> > I'm not really sure if this is a bug or not, but I do find it odd that the behavior is something like: "If origin does not understand byte-range requests, then I also shouldn't understand them".
> >
> > Is there a way to solve this on the nginx side directly to "fix" origin servers that do not send an Accept-Ranges header, or is it something that could possibly be fixed in such a way that nginx doesn't "require" the cached file to contain the "Accept-Ranges: bytes" header, to be able to do range requests to it?
>
> The "proxy_force_ranges" directive enables byte ranges regardless of the
> Accept-Ranges header.
>
> http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_force_ranges
>
> --
> Roman Arutyunyan
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
--
Roman Arutyunyan
More information about the nginx
mailing list