# Entire content is cached but when client pulls a byte range the entire file is sent

**URL:** <https://www.ruby-forum.com/t/entire-content-is-cached-but-when-client-pulls-a-byte-range-the-entire-file-is-sent/244196>\
**Category:** NGINX\
**Created:** [March 3, 2016, 7:55pm UTC](https://www.ruby-forum.com/t/entire-content-is-cached-but-when-client-pulls-a-byte-range-the-entire-file-is-sent/244196 "2016-03-03T19:55:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [March 3, 2016, 7:55pm UTC](https://www.ruby-forum.com/t/entire-content-is-cached-but-when-client-pulls-a-byte-range-the-entire-file-is-sent/244196/1 "2016-03-03T19:55:52Z")

</div>

Can the client pull a subset of the content from the cached content?

If it can pull a subset of the content via byte range requests can you  
point me to how to configure nginx to allow this…?

This is what is stored in cache on the nginx server.

[root@gemini-sled1 ac]# strings 81f71da53616b454815b570216041ac7 | more  
KEY: GET/atis/vod/0x1051e69a101e9/d4\_HDFD0075260002446163-8320285.mpg  
HTTP/1.1 206 Partial Content  
Server: Cisco/CDS Gateway/3.0  
Connection: close  
Content-Type: video/mpeg  
Content-Length: 597600300  
Content-Range: bytes 0-597600299/597600300  
Cache-Control: public

But when the client attempt to pull a byte range the entire file is  
pulled.

curl -v -o /dev/null -r 1000-1001  
[http://10.157.66.194/atis/vod/0x1051e69a101e9/d4\_HDFD0075260002446163-8320285.mpg](http://10.157.66.194/atis/vod/0x1051e69a101e9/d4_HDFD0075260002446163-8320285.mpg)

- About to connect() to 10.157.66.194 port 80
- Trying 10.157.66.194… connected
- Connected to 10.157.66.194 (10.157.66.194) port 80

> GET /atis/vod/0x1051e69a101e9/d4\_HDFD0075260002446163-8320285.mpg HTTP/1.1  
> Range: bytes=1000-1001  
> User-Agent: curl/7.15.5 (x86\_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b  
> zlib/1.2.3 libidn/0.6.5  
> Host: 10.157.66.194  
> Accept: _/_

\< HTTP/1.1 206 Partial Content  
\< Server: nginx/1.9.9  
\< Date: Thu, 03 Mar 2016 18:36:05 GMT  
\< Content-Type: video/mpeg  
\< Content-Length: 597600300  
\< Connection: keep-alive  
\< Content-Range: bytes 0-597600299/597600300  
\< Cache-Control: public  
\< Link:  
[http://atisdemo.atge.twcable.com/atis/vod/d4\_HDFD0075260002446163-8320285.mpg.mrm](http://atisdemo.atge.twcable.com/atis/vod/d4_HDFD0075260002446163-8320285.mpg.mrm);  
rel=“[http://www.iif.atis.com/c2-media-resource-metadata](http://www.iif.atis.com/c2-media-resource-metadata)”  
% Total % Received % Xferd Average Speed Time Time Time  
Current  
Dload Upload Total Spent Left  
Speed  
100 569M 100 569M 0 0 3758k 0 0:02:35 0:02:35 --:–:–  
4054k

We have nginx version 1.9.9 installed.

Nginx.conf

user nginx;  
worker\_processes 1;

error\_log /var/log/nginx/error.log warn;  
pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;

```
log_format main '$remote_addr - $remote_user [$time_local] 

```

“$request” ’  
'$status $body\_bytes\_sent “$http\_referer” ’  
'“$http\_user\_agent” “$http\_x\_forwarded\_for” “$uri”  
“$request\_uri” “$request\_completion” “$cookie\_session” “$http\_cookie”  
“$http\_host” “$host” “$server\_port” “$proxy\_add\_x\_forwarded\_for” ';

```
access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;

#keepalive_timeout 65;

proxy_http_version 1.1;
proxy_cache_methods GET HEAD POST;
proxy_pass_request_headers on;
fastcgi_buffers 8 160k;
fastcgi_buffer_size 320k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;

#proxy_cache_path /arroyo/nginxtest/sample/atis/vod levels=1:2 

```

keys\_zone=my-cache:80m  
proxy\_cache\_path /cache1 levels=1:2 keys\_zone=my-cache:80m  
max\_size=2g inactive=6000m use\_temp\_path=off;  
#proxy\_temp\_path /var/cache/tmp;

```
proxy_force_ranges on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_key "$request_method$request_uri";

proxy_cache my-cache;
proxy_cache_valid 200 206 1d;
proxy_cache_valid 404 1m;

proxy_next_upstream error timeout invalid_header http_500 http_502 

```

http\_503 http\_504;

```
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;

include /etc/nginx/conf.d/*.conf;

```

}

Default.conf

#resolve these upstream servers in /etc/hosts  
upstream server\_array {  
server 10.155.202.125:80;  
}

server {  
listen 10.157.66.194:80; #local ip:port for nginx  
to listen  
server\_name [atisdemo.atge.twcable.com](http://atisdemo.atge.twcable.com);  
max\_ranges 4;  
proxy\_force\_ranges on;  
location / {  
limit\_rate\_after 10k;  
set $limit\_rate 3750k;  
proxy\_intercept\_errors on;  
proxy\_pass http://server\_array;  
error\_page 302 = @locationupstream;  
}  
location @locationupstream{  
rewrite\_log on;  
set $limit\_rate 3750k;  
set $upstreamlocation ‘$upstream\_http\_location’;  
proxy\_set\_header Range $http\_range;  
proxy\_set\_header “User-Agent” “Cisco/CDS Gateway/3.0”;  
proxy\_pass\_header Server;  
proxy\_pass $upstreamlocation;  
proxy\_force\_ranges on;  
}  
}

Todd Wilson

* * *

This E-mail and any of its attachments may contain Time Warner Cable  
proprietary information, which is privileged, confidential, or subject  
to copyright belonging to Time Warner Cable. This E-mail is intended  
solely for the use of the individual or entity to which it is addressed.  
If you are not the intended recipient of this E-mail, you are hereby  
notified that any dissemination, distribution, copying, or action taken  
in relation to the contents of and attachments to this E-mail is  
strictly prohibited and may be unlawful. If you have received this  
E-mail in error, please notify the sender immediately and permanently  
delete the original and any copy of this E-mail and any printout.
