Nginx:作为缓存,支持Range回源

一、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回源。

二、缓存配置文件

[plain]  view plain  copy
  1. #user  nobody;  
  2. worker_processes  1;  
  3.   
  4. events {  
  5.     worker_connections  1024;  
  6. }  
  7.   
  8.   
  9. http {  
  10.     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
  11.                       '$status $body_bytes_sent "$http_referer" '  
  12.                       '"$http_user_agent" "$http_x_forwarded_for"';  
  13.   
  14.     access_log  logs/access.log  main;  
  15.   
  16.     sendfile        on;  
  17.   
  18.     keepalive_timeout  65;  
  19.   
  20.     #cache  
  21.     proxy_cache_path /data/cache  
  22.                 keys_zone=cache_my:100m  
  23.                 levels=1:1  
  24.                 inactive=12d  
  25.                 max_size=200m;  
  26.   
  27.     server {  
  28.         listen       80;  
  29.         server_name  localhost;  
  30.   
  31.         location / {  
  32.                 #slice  
  33.                 slice 1k;  
  34.                 proxy_cache cache_my;  
  35.                 proxy_cache_key $uri$is_args$args$slice_range;  
  36.                 add_header X-Cache-Status $upstream_cache_status;  
  37.                 proxy_set_header Range $slice_range;  
  38.                 proxy_cache_valid 200 206 3h;  
  39.                 proxy_pass http://192.168.175.135:80;  
  40.   
  41.                 proxy_cache_purge PURGE from 127.0.0.1;  
  42.         }  
  43.     }  
  44. }  

三、运行结果

查看的是源站的日志

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

猜你喜欢

转载自blog.csdn.net/ai2000ai/article/details/80256362