varnish配置文件

post by rocdk890 / 2013-4-10 23:10 Wednesday linux技术

 转了一位大神的varnish 3.0的配置文件,我居然不记得是在那复制的了,希望原作者原谅.

    #Cache for linuxtone sites 
    #backend vhost 
    backend  slogra { 
    .host = "blog.slogra.com"; 
    .port = "80"; 
    } 
    #acl 
    acl purge { 
      "localhost"; 
      "127.0.0.1"; 
      "192.168.0.0"/24; 
    } 
    sub vcl_recv { 
            if (req.http.Accept-Encoding) { 
                if (req.url ~ "\.(jpg|png|gif|jpeg|flv)$" ) { 
                    remove req.http.Accept-Encoding; 
                    remove req.http.Cookie; 
                } else if (req.http.Accept-Encoding ~ "gzip") { 
                    set req.http.Accept-Encoding = "gzip"; 
                } else if (req.http.Accept-Encoding ~ "deflate") { 
                    set req.http.Accept-Encoding = "deflate"; 
                } else { 
                    remove req.http.Accept-Encoding; 
                } 
            } 
               if (req.http.host ~  "(.*)slogra.com") { 
                           set req.backend = slogra; 
                     } 
                else { 
                            error 404 "This website is maintaining or not exist!"; 
                    } 
      if (req.request == "PURGE") { 
         if (!client.ip ~purge) { 
           error 405 "Not Allowed"; 
       } 
    #.dd..... 
       return(lookup); 
      } 
    #...GET...url...jpg,png,gif. ..cookie 
      if (req.request == "GET"&& req.url ~ "\.

(png|gif|jpeg|jpg|ico|swf|css|js|html|htm|gz|tgz|bz2|tbz|mp3|ogg|mp4|flv|f4v|pdf)$") { 
            unset req.http.cookie; 
      } 
    #..GET...url.php....cache.... 
      if (req.request =="GET"&&req.url ~ "\.php($|\?)"){ 
            return (pass); 
      } 
    #     if (req.restarts == 0) { 
            if (req.http.x-forwarded-for) { 
                set req.http.X-Forwarded-For = 
                    req.http.X-Forwarded-For + ", " + client.ip; 
            } else { 
                set req.http.X-Forwarded-For = client.ip; 
            } 
    #   } 
    #........pipe.. 
        if (req.request != "GET" && 
          req.request != "HEAD" && 
          req.request != "PUT" && 
          req.request != "POST" && 
          req.request != "TRACE" && 
          req.request != "OPTIONS" && 
          req.request != "DELETE") { 
            return (pipe); 
        } 
    #..GET .HEAD..... 
        if (req.request != "GET" && req.request != "HEAD") { 
            return (pass); 
        } 
        if (req.http.Authorization) { 
            return (pass); 
        } 
        return (lookup); 
    } 
    #..url+host hash...... 
    sub vcl_hash { 
        hash_data(req.url); 
        if (req.http.host) { 
            hash_data(req.http.host); 
        } else { 
            hash_data(server.ip); 
        } 
        return (hash); 
    } 
    # .....purge ..... 
    sub vcl_hit { 
       if (req.request == "PURGE") { 
           set obj.ttl = 0s; 
           error 200 "Purged"; 
        } 
        return (deliver); 
    } 
    sub vcl_fetch { 
              if (req.url ~ "\.(jpeg|jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|ico|swf|flv|dmg|js|css|html|htm)$") { 
                       set beresp.ttl = 2d; 
                       set beresp.http.expires = beresp.ttl; 
                       set beresp.http.Cache-Control = "max-age=172800"; 
                       unset beresp.http.set-cookie; 
              } 
              if (req.url ~ "\.(dmg|js|css|html|htm)$") { 
                       set beresp.do_gzip = true; 
              } 
              if (beresp.status == 503) { 
                             set beresp.saintmode = 15s; 
              } 
    } 
    sub vcl_deliver { 
            set resp.http.x-hits = obj.hits ; 
            if (obj.hits > 0) { 
                    set resp.http.X-Cache = "HIT You!"; 
            } else { 
                    set resp.http.X-Cache = "MISS Me!"; 
            } 
    } 

夜空- 本站版权
1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-336.html

标签: 配置 varnish 文件 Config 3.0

评论: