首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Varnish.4.x不缓存范围请求

Varnish.4.x不缓存范围请求
EN

Stack Overflow用户
提问于 2015-07-10 16:33:47
回答 2查看 833关注 0票数 0

我们正在尝试让Varnish缓存range请求。我们使用的是Varnish 4.0。

我们有以下配置

VCL4.0;

代码语言:javascript
复制
import std;

# Default backend definition. Set this to point to your content server.
backend default {
    .host = "194.142.x.x";
    .port = "8008";
}

sub vcl_recv {

if (req.url ~ "(?i)\.(png|avi|mkv|mp4)(\?[a-z0-9]+)?$") {
    unset req.http.Cookie;
  }
    # Happens before we check if we have this in cache already.
    #
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.

  set req.http.host = regsub(req.http.host, "v\.","\rms\.");

  std.log("REWRITED TO"+req.http.host+"  "+req.url);



}

sub vcl_backend_response {
    # Happens after we have read the response headers from the backend.
    #
    # Here you clean the response headers, removing silly Set-Cookie headers
    # and other mistakes your backend does.
}

sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    #
                                                               vcl 4.0;

import std;

# Default backend definition. Set this to point to your content server.
backend default {
    .host = "194.142.x.x";
    .port = "8008";
}

sub vcl_recv {

if (req.url ~ "(?i)\.(png|avi|mkv|mp4)(\?[a-z0-9]+)?$") {
    unset req.http.Cookie;
  }
    # Happens before we check if we have this in cache already.
    #
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.

  set req.http.host = regsub(req.http.host, "v\.","\rms\.");

  std.log("REWRITED TO"+req.http.host+"  "+req.url);



}

sub vcl_backend_response {
    # Happens after we have read the response headers from the backend.
    #
    # Here you clean the response headers, removing silly Set-Cookie headers
    # and other mistakes your backend does.
}

sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    #

然而,range请求花费了太长的时间来服务,所以我们觉得它没有被缓存,因为原始服务器被击中了。

EN

回答 2

Stack Overflow用户

发布于 2015-10-07 05:05:35

你能解决这个问题吗?

我非常确定块配置:

代码语言:javascript
复制
if (req.url ~ "(?i)\.(png|avi|mkv|mp4)(\?[a-z0-9]+)?$") {
    unset req.http.Cookie;
  }
    # Happens before we check if we have this in cache already.
    #
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.

  set req.http.host = regsub(req.http.host, "v\.","\rms\.");
  std.log("REWRITED TO"+req.http.host+"  "+req.url);

处于错误的位置,需要在vcl_backend_response中而不是在vcl_recv中

票数 1
EN

Stack Overflow用户

发布于 2018-09-03 00:08:46

Caching partial objects with varnish 4.0

代码语言:javascript
复制
sub vcl_recv {
    if (req.http.Range ~ "bytes=") {
        set req.http.x-range = req.http.Range;
    }
}

sub vcl_hash {
    if (req.http.x-range ~ "bytes=") {
            hash_data(req.http.x-range);
            unset req.http.Range;
    }
}

sub vcl_backend_fetch {
    if (bereq.http.x-range) {
        set bereq.http.Range = bereq.http.x-range;
    }
}

sub vcl_backend_response {
    if (bereq.http.x-range ~ "bytes=" && beresp.status == 206) {
        set beresp.ttl = 10m;
        set beresp.http.CR = beresp.http.content-range;
    }
}

sub vcl_deliver {
    if (resp.http.CR) {
        set resp.http.Content-Range = resp.http.CR;
        unset resp.http.CR;
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31336069

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档