Our web server is a very old version, and doesn't support byte range download. So I am planning to use nginx for the media download url. The nginx cache seems ok, but the byte range doesn't work. It always returns the whole file.
proxy_cache_path /tmp/cache keys_zone=IMAGE:10m inactive=24h;
...
location /api/v2/image_proxy/blobs/ {
proxy_set_header X-NginX-Proxy true;
proxy_set_header Host www.my.com;
proxy_buffering on;
proxy_cache IMAGE;
proxy_cache_valid 200 1d;
proxy_ssl_server_name on;
proxy_force_ranges on;
proxy_ignore_headers Expires;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_hide_header X-Accel-Expires;
proxy_hide_header Expires;
proxy_hide_header Cache-Control;
proxy_hide_header Pragma;
proxy_pass https://www.my.com/api/v2/image_proxy/blobs/;
}
And the testing curl outputs:
% curl --range 1000-1099 -v -O "http://localhost:8088/api/v2/image_proxy/blobs/eyJf...150/mini_magick20211102-21-1u44964"
* Trying 127.0.0.1:8088...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to localhost (127.0.0.1) port 8088 (#0)
> GET /api/v2/image_proxy/blobs/eyJfc...bd5150/mini_magick20211102-21-1u44964 HTTP/1.1
> Host: localhost:8088
> Range: bytes=1000-1099
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: nginx
< Date: Fri, 16 Sep 2022 06:48:14 GMT
< Content-Type: image/jpeg
< Transfer-Encoding: chunked
< Connection: keep-alive
< x-frame-options: SAMEORIGIN
< x-xss-protection: 1; mode=block
< x-content-type-options: nosniff
< x-download-options: noopen
< x-permitted-cross-domain-policies: none
< referrer-policy: strict-origin-when-cross-origin
< etag: W/"d9d06b623f4706fc0886ece3e5057379"
< last-modified: Sat, 01 Jan 2011 00:00:00 GMT
< content-disposition: inline; filename="mini_magick20211102-21-1u44964"; filename*=UTF-8''mini_magick20211102-21-1u44964
< x-request-id: dee37c0f315e5d66d6d0210b05423620
< x-runtime: 0.168270
< strict-transport-security: max-age=31536000; includeSubDomains
< vary: Origin
< CF-Cache-Status: DYNAMIC
< Set-Cookie: __cf_bm=ZEuX7...
< Set-Cookie: _cfuvid=yU...
< CF-RAY: 74...-FRA
< alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
< Accept-Ranges: bytes
<
{ [13052 bytes data]
100 135k 0 135k 0 0 5259k 0 --:--:-- --:--:-- --:--:-- 10.1M
Later, I tried on some ibm image, and the same config. seems working:
% curl --range 100-103 -v -O "http://localhost:8088/test"
* Trying 127.0.0.1:8088...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to localhost (127.0.0.1) port 8088 (#0)
> GET /test HTTP/1.1
> Host: localhost:8088
> Range: bytes=100-103
> User-Agent: curl/7.79.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 206 Partial Content
< Server: nginx
< Date: Fri, 16 Sep 2022 06:45:06 GMT
< Content-Type: image/png
< Content-Length: 4
< Connection: keep-alive
< Last-Modified: Mon, 30 Nov 2020 17:02:57 GMT
< ETag: "365a-5b555fb543240"
< x-content-type-options: nosniff
< X-XSS-Protection: 1; mode=block
< Content-Security-Policy: upgrade-insecure-requests
< Strict-Transport-Security: max-age=31536000
< Accept-Ranges: bytes
< Content-Range: bytes 100-103/13914
<
{ [4 bytes data]
100 4 100 4 0 0 75 0 --:--:-- --:--:-- --:--:-- 125
BTW, the byte range support is a must to play on apple devices.