Opened 7 years ago

Closed 7 years ago

#1304 closed defect (invalid)

proxy_cache not support slice

Reported by: yan.sheng.upai.com@… Owned by:
Priority: minor Milestone:
Component: other Version: 1.11.x
Keywords: Cc:
uname -a: #1 SMP Thu Jun 23 17:05:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.11.6

Description

config:

proxy_cache_path /root/cjhust/cache levels=1:2 keys_zone=cjhust:100m inactive=2h max_size=10g;

server {

listen 7000;

location / {

expires 30s;
root html;

}

}

server {

listen 8001;
proxy_cache cjhust;

location / {

slice 256k;
proxy_set_header range $slice_range;
proxy_pass http://127.0.0.1:7000;

}

}

first test: result is OK

#curl http://127.0.0.1:8001/512K.mp3 -r 1-5 -v

  • About to connect() to 127.0.0.1 port 8001 (#0)
  • Trying 127.0.0.1...
  • Connected to 127.0.0.1 (127.0.0.1) port 8001 (#0)

    GET /512K.mp3 HTTP/1.1
    Range: bytes=1-5
    User-Agent: curl/7.29.0
    Host: 127.0.0.1:8001
    Accept: */*

< HTTP/1.1 206 Partial Content
< Server: nginx/1.11.6
< Date: Thu, 29 Jun 2017 02:56:17 GMT
< Content-Type: audio/mpeg
< Content-Length: 5
< Connection: keep-alive
< Last-Modified: Thu, 22 Jun 2017 06:53:07 GMT
< ETag: "594b6953-7d000"
< Expires: Thu, 29 Jun 2017 02:56:47 GMT
< Cache-Control: max-age=30
< Content-Range: bytes 1-5/512000
<

  • Connection #0 to host 127.0.0.1 left intact

second test: result is ERROR

#curl http://127.0.0.1:8001/512K.mp3 -r 1-5 -v

  • About to connect() to 127.0.0.1 port 8001 (#0)
  • Trying 127.0.0.1...
  • Connected to 127.0.0.1 (127.0.0.1) port 8001 (#0)

    GET /512K.mp3 HTTP/1.1
    Range: bytes=1-5
    User-Agent: curl/7.29.0
    Host: 127.0.0.1:8001
    Accept: */*

< HTTP/1.1 206 Partial Content
< Server: nginx/1.11.6
< Date: Thu, 29 Jun 2017 02:56:24 GMT
< Content-Type: audio/mpeg
< Content-Length: 262144
< Connection: keep-alive
< Last-Modified: Thu, 22 Jun 2017 06:53:07 GMT
< ETag: "594b6953-7d000"
< Expires: Thu, 29 Jun 2017 02:56:47 GMT
< Cache-Control: max-age=30
< Content-Range: bytes 0-262143/512000
<

  • Connection #0 to host 127.0.0.1 left intact

Change History (1)

comment:1 by Maxim Dounin, 7 years ago

Resolution: invalid
Status: newclosed

Please read the documentation:

... If caching is enabled, $slice_range should be added to the cache key and caching of responses with 206 status code should be enabled.

In your configuration you do not include $slice_range into the cache key, and as a result slice filter doesn't know it should handle a response, so a response from cache is simply returned as is.

Note: See TracTickets for help on using tickets.