2017-02-19 90 views
0

我有一个基本的default.vcl为我的网站,它工作。添加移动检测清漆{default.vcl}后,清漆不启动

我添加了下面的代码来检测并为用户提供不同的主题,如果来自PC或手机。添加下面的代码来检测移动设备后,清漆不会启动。

如何解决这个问题,从而清漆检测到移动设备,因此,如果从手机访问移动主题是在同一个URL提供服务,表



    /* 
    * 
    * First, set up a backend to answer the request if there's not a cache hit. 
    * 
    */ 
    backend default { 

     # Set a host. 
     .host = "xx.xx.xx.xx"; 

     # Set a port. 80 is normal Web traffic. 
     .port = "xxxx"; 
    } 
    /* 
    * 
    * Next, configure the "receive" subroutine. 
    * 
    */ 
    acl admin_ip { 
     "xx.xx.xx.xx"; 
    } 
    include "devicedetect.vcl"; 
    sub vcl_recv { 
      call devicedetect; 
      if (req.request == "PURGE") { 
      if (!client.ip ~ admin_ip) { 
       error 405 "You can't do this, muggle!"; 
      } 
       return(lookup); 
     } 
    if (!req.backend.healthy) { 
     unset req.http.Cookie; 
     } 
    set req.http.X-Forwarded-For = client.ip; 

     # Use the backend we set up above to answer the request if it's not cached. 
     #set req.backend = default; 

     if (req.url ~ "^/user/login" || 
      req.url ~ "^/oc-admin" || 
      req.url ~ "^/item/new" || 
      req.request == "POST") 
     { 
      return (pass); 
     } 
     if (req.url ~ "(?i)\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js)(\?.*)?$") { 
     unset req.http.Cookie; 
     unset req.http.Cache-Control; 
     unset req.http.Max-Age; 
     unset req.http.Pragma; 
     unset req.http.Cookie; 
     } 
     if(req.http.Cookie) { 
     if (req.http.Cookie !~ "(sessionid|XXXid)") { 
      remove req.http.Cookie; 
     } 
     } 
     # Pass the request along to lookup to see if it's in the cache. 
     return(lookup); 
    } 
    /* 
    * 
    * Next, let's set up the subroutine to deal with cache misses. 
    * 
    */ 
    sub vcl_miss { 

     # We're not doing anything fancy. Just pass the request along to the 
     # subroutine which will fetch something from the backend. 
     return(fetch); 
    } 
    /* 
    * 
    * Now, let's set up a subroutine to deal with cache hits. 
    * 
    */ 
    sub vcl_hit { 

     # Again, nothing fancy. Just pass the request along to the subroutine 
     # which will deliver a result from the cache. 
     return(deliver); 
    } 
    /* 
    * 
    * This is the subroutine which will fetch a response from the backend. 
    * It's pretty fancy because this is where the basic logic for caching is set. 
    * 
    */ 
    sub vcl_fetch { 

    if (req.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"; 
      } 
     } 
     #unset beresp.http.expires; # for cloudfront since it prefers cache-control 
            # header over expires 

     if (req.url ~ "(?i)\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js)(\?.*)?$") { 
     unset beresp.http.set-cookie; 
     } 
     if (req.http.Content-Type ~ "(image|audio|video|pdf|flash)") { 
      set beresp.do_gzip = false; 
     } 
     if (req.http.Content-Type ~ "text") { 
      set beresp.do_gzip = true; 
     } 
     # Varnish determined the object was not cacheable 
     if (beresp.ttl 0) { 
     set resp.http.X-Varnish-Cache = "HIT"; 
     } 
     else { 
     set resp.http.X-Varnish-Cache = "MISS"; 
     } 

     return (deliver); 
    } 

回答

0

,你可以尝试使用启动清漆

varnishd -F -f /etc/varnish/default.vcl 

所以你可以看到所有的消息/错误。顺便说一句:你包括一个devicedetect.vcl。没有这个文件,很难说出了什么问题;)

+0

使用上面提到的命令后,它显示我喜欢# Varnish determined the object was not cacheable if (beresp.ttl 0) { set resp.http.X-Varnish-Cache = "HIT"; } else { set resp.http.X-Varnish-Cache = "MISS"; }错误,所以我改变这个(beresp.ttl 0 as(beresp.ttl> = 0s)但它没有任何cahing –

+0

设备检测VCL是[链接](https://github.com/varnishcache/varnish-devicedetect/blob/master/devicedetect.vcl) –