生活随笔
收集整理的這篇文章主要介紹了
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 plaincopy
#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
總結
以上是生活随笔為你收集整理的Nginx:作为缓存,支持Range回源的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。