2016-02-22 49 views
0

我有一个问题,我无法找到它来自哪里。光油忽略ttl

我在使用Nginx的专用服务器上使用Varnish Cache,并将网站重定向到其后端。

即使我为每个页面定义了不同的ttl,定义的ttl被忽略或旁路或其他东西,所有的东西都像是对事物的期望,所有页面都被缓存了2分钟。

这里是我的配置:

的/ etc /清漆/ vcl_backend_response:

#example.com: 
if (beresp.http.host == "example.com" || beresp.http.host == "www.example.com") { 
include "/etc/varnish/backend_response/example.conf"; 
} 
return(deliver); 

     set beresp.http.Vary = "Accept-Encoding"; 
     set beresp.ttl = 1h; 

     if (beresp.ttl <= 0s || 
       beresp.http.Set-Cookie || 
       beresp.http.Vary == "*") { 
       set beresp.ttl = 120 s; 
       set beresp.uncacheable = true; 
       return (deliver); 
     } 

     unset beresp.http.Server; 
     set beresp.http.Server = "Microsoft IIS/7.5"; 

    if (beresp.http.content-type ~ "text") { 
     set beresp.do_gzip = true; 
    } 

    if (bereq.http.X-UA-Device) { 
     if (!beresp.http.Vary) { # no Vary at all 
      set beresp.http.Vary = "X-UA-Device"; 
     } elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary 
      set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device"; 
     } 
    } 
     set beresp.http.X-UA-Device = bereq.http.X-UA-Device; 
     set beresp.grace = 2h; 

} 

/etc/varnish/backend_response/example.conf

if (bereq.url ~ "(?i)\.(css|bmp|tif|ttf|docx|woff2|js|pict|tiff|eot|xlsx|jpg|csv|eps|woff|xls|jpeg|doc|ejs|otf|pptx|gif|pdf|swf|svg|ps|ico|pls|midi|svgz|class|png|ppt|mid|webp|jar)(\?[a-zA-Z0-9\=\.\-]+)?$") { 
     set beresp.ttl = 4h; 
     unset beresp.http.expires; 
     set beresp.http.cache-control = "max-age=345600"; 
     set beresp.http.magicmarker = "1"; 
     set beresp.grace = 300m; 
     set beresp.do_gzip = true; 
} elseif(bereq.url == "/") { 
     set beresp.ttl = 1m; 
     set beresp.grace = 300m; 
     set beresp.do_gzip = true; 
} else { 
     set beresp.ttl = 5m; 
     set beresp.grace = 300m; 
     set beresp.do_gzip = true; 
} 

首页缓存为1M和剩下的页面是5米,但由于不明原因,所有缓存为2米。

/etc/varnish/vcl_recv.conf:

sub vcl_recv { 

#exmaple.com: 
     if (req.http.host == "exmaple.com" || req.http.host == "www.exmaple.com") { 
       set req.backend_hint = exmaple; 
       include "/etc/varnish/recv/exmaple.conf"; 
     } 

include "/etc/varnish/recv/global.conf"; 
    unset req.http.cookie; 
    unset req.http.Accept-Encoding; 

call identify_device; 

     if (req.method != "GET" && req.method != "HEAD") { 
       return (pass); 
     } 

     if (req.http.Authorization || req.http.Cookie) { 
       return (pass); 
     } 

     if (req.http.Accept-Encoding) { 
       if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") { 
         unset req.http.Accept-Encoding; 
       } elseif (req.http.Accept-Encoding ~ "gzip") { 
         set req.http.Accept-Encoding = "gzip"; 
       } elsif (req.http.Accept-Encoding ~ "deflate") { 
         set req.http.Accept-Encoding = "deflate"; 
       } else { 
         unset req.http.Accept-Encoding; 
       } 
     } 

     if (req.http.Cookie) { 
       set req.http.Cookie = regsuball(req.http.Cookie, "(^|(?<=;)) *__utm.=[^;]+;? *", "\1"); 

       if (req.http.Cookie == "PHPSESSID|LOGIN") { 
         unset req.http.Cookie; 
       } 
     } 

} 

/etc/varnish/recv/exmaple.conf:

if (req.http.x-forwarded-for) { 
     set req.http.X-Forwarded-For = req.http.X-Forwarded-For; 
} else { 
     set req.http.X-Forwarded-For = client.ip; 
} 
if (req.method != "GET" && req.method != "HEAD") { 
     return(pass); 
} 
if (req.url ~ "(?i)\.(css|bmp|tif|ttf|docx|woff2|js|pict|tiff|eot|xlsx|jpg|csv|eps|woff|xls|jpeg|doc|ejs|otf|pptx|gif|pdf|swf|svg|ps|ico|pls|midi|svgz|class|png|ppt|mid|webp|jar)(\?[a-zA-Z0-9\=\.\-]+)?$") { 
     unset req.http.cookie; 
     return (hash); 
} elseif (req.url ~ "/custom-page") { 
     return (pass); 
} elseif (req.url == "/") { 
     return (hash); 
} else { 
     return (hash); 
} 

任何线索?

在此先感谢。

回答

0

您的代码始终输入此if块,因此将ttl设置为120s。做检查正在评估为true的3个条件,一个或多个(由if条件逐一删除它们)

if (beresp.ttl <= 0s || 
       beresp.http.Set-Cookie || 
       beresp.http.Vary == "*") { 
       set beresp.ttl = 120 s; 
       set beresp.uncacheable = true; 
       return (deliver); 
     } 
+0

试图彻底,仍然缓存2分钟,任何想法删除此条件? –