一、Range回源
1.1 Nginx的Range回源、ngx_http_slice_module模块、--with-http_slice_module参数
Nginx的ngx_http_slice_module模块是用来支持Range回源的。
ngx_http_slice_module从Nginx的1.9.8版本开始有的。
启用ngx_http_slice_module模块需要在编译Nginx时,加参数--with-http_slice_module。
1.2 curl指定Range范围
-r 指定Range的范围
1.3 HTTP 206
HTTP的Range请求,成功返回时的状态码是206。
1.4 架构
缓存、源站
用户向缓存请求URL,缓存进行Range回源。
二、缓存配置文件
- #user nobody;
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- access_log logs/access.log main;
- sendfile on;
- keepalive_timeout 65;
- #cache
- proxy_cache_path /data/cache
- keys_zone=cache_my:100m
- levels=1:1
- inactive=12d
- max_size=200m;
- server {
- listen 80;
- server_name localhost;
- location / {
- #slice
- slice 1k;
- proxy_cache cache_my;
- proxy_cache_key $uri$is_args$args$slice_range;
- add_header X-Cache-Status $upstream_cache_status;
- proxy_set_header Range $slice_range;
- proxy_cache_valid 200 206 3h;
- proxy_pass http://192.168.175.135:80;
- proxy_cache_purge PURGE from 127.0.0.1;
- }
- }
- }
三、运行结果
查看的是源站的日志
index.html文件大小为5196
curl www.guowenyan.cn/index.html -r 0-1024
curl www.guowenyan.cn/index.html
参考资料:
官网ngx_http_slice_module:http://nginx.org/en/docs/http/ngx_http_slice_module.html