Welcome! Log In Create A New Profile

Advanced

nginx & Range header & proxy cache

Richard Kearsley
September 13, 2011 06:30AM
Hi
If a Range request is sent to nginx proxy (e.g. header "Range: bytes=50-") and the file isn't in cache yet (cache MISS), the range is ignored and full file sent
When the file has been cached (cache HIT), Range request works as expected

Is this the intended behaviour?

Please consider the following example

# /usr/local/nginx/sbin/nginx -V
nginx: nginx version: nginx/1.0.6
nginx: built by gcc 4.4.5 (Debian 4.4.5-8)
nginx: configure arguments:

error_log logs/error-small.log;
worker_processes 2;
events
{
use epoll;
worker_connections 16384;
}

http
{
include mime.types;
default_type application/octet-stream;
keepalive_timeout 65;
proxy_cache_path /var/cache/nginx levels=2:2:2 keys_zone=small:512m inactive=24h max_size=128G;
resolver 8.8.8.8;

server
{
listen 80;
server_name _;
location /
{
proxy_pass http://$http_X_Backend:$http_X_Backend_Port;
proxy_cache small;
proxy_cache_valid 200 302 10y;
proxy_cache_valid 404 10m;
proxy_cache_key $uri;
proxy_cache_min_uses 10;
proxy_cache_use_stale updating;
add_header X-Cached $upstream_cache_status;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html
{
root html;
}
}
}


# wget -SO /dev/null --header="X-Backend: download.thinkbroadband.com" --header="X-Backend-Port: 80" --header="Range: bytes=50-" localhost/5MB..zip
--2011-09-13 11:33:45-- http://localhost/5MB.zip
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|127.0.0.1|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: nginx/1.0.6
Date: Tue, 13 Sep 2011 10:33:45 GMT
Content-Type: application/zip
Connection: keep-alive
Last-Modified: Mon, 02 Jun 2008 15:30:42 GMT
ETag: "11f000b-500000-44eb0adaf4c80"
Accept-Ranges: bytes
Content-Length: 5242880
X-Cached: MISS
Length: 5242880 (5.0M) [application/zip]
Saving to: `/dev/null'

(try 9 more times to get it cached)

# wget -SO /dev/null --header="X-Backend: download.thinkbroadband.com" --header="X-Backend-Port: 80" --header="Range: bytes=50-" localhost/5MB..zip
--2011-09-13 11:33:11-- http://localhost/5MB.zip
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|127.0.0.1|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 206 Partial Content
Server: nginx/1.0.6
Date: Tue, 13 Sep 2011 10:33:11 GMT
Content-Type: application/zip
Content-Length: 5242830
Connection: keep-alive
Last-Modified: Mon, 02 Jun 2008 15:30:42 GMT
ETag: "11f000b-500000-44eb0adaf4c80"
X-Cached: HIT
Content-Range: bytes 50-5242879/5242880
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

nginx & Range header & proxy cache

Richard Kearsley September 13, 2011 06:30AM

Re: nginx & Range header & proxy cache

Maxim Dounin September 13, 2011 06:32AM

RE: nginx & Range header & proxy cache

Richard Kearsley September 13, 2011 07:58AM

RE: nginx & Range header & proxy cache

Richard Kearsley September 13, 2011 12:06PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 77
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready