zoukankan      html  css  js  c++  java
  • varnish中忽略cookie进行缓存

    varnish不缓存cookie的页面,如果html页面中带有cookie
    以下代码为接收到结尾的文件,自动去除掉cookie
    sub vcl_recv {
        if (req.request == ”GET” && req.url ~ ”.(js|css|html|jpg|png|gif|swf|jpeg| ico)$”) {

         unset req.http.cookie;

        }
    }

    对于php的session页面,以下配置可以强制缓存
    sub vcl_recv {
        unset req.http.Cookie;
        return (lookup);
    }
    sub vcl_fetch {
        unset beresp.http.Set-Cookie;
        return(deliver);
    }


    同时需要在php页面中设置session使用缓存
    session_cache_limiter('');
    header('Cache-Control: public, s-maxage=60');
    session_start();


    以下为详细配置

    #cache config
    backend default {
         .host = "192.168.1.110";
         .port = "1300";
    }

    sub vcl_recv{
      #clear cookie

       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;
       }

       if(req.url ~ "/Index/verify$" || req.url ~ "/Index/logindo"){

      }else{

            if( req.http.Cookie ~"authkey" ){

      }else{
          unset req.http.cookie;
          return (lookup);
      }
        }

    }

    sub vcl_deliver {
            set resp.http.x-hits = obj.hits ;

            if (obj.hits > 0) {
                    set resp.http.X-Cache = "HIT read.easouu.com";
            }else {
                    set resp.http.X-Cache = "MISS read.easou.com";
            }

    }

    sub vcl_fetch{
        #clear no-cache

     if(req.url ~ "/Index/verify$" || req.url ~ "/Index/logindo"){
     
      }else{
     
       if( req.http.Cookie ~"authkey" ){
     
       }else{
           unset req.http.cookie;
           return (deliver);
       }
     
     
     }
    }

  • 相关阅读:
    MongoDB+Lucence.net
    hubble+sqlserver
    C# 设计模式 1 接口模式 1.1 适配器模式 IT
    SQLServer2005 中 XML类型方法中 XQuery中变量的参数化匆忙整理 IT
    DoNET 类库设计准则01 名称规则 IT
    GMRES在matlab中的描述
    矩阵良态与病态
    调试vc++的一点感悟
    基于GramSchmidt正交法的广义极小残量法(GMRES)
    VC6 vs2003 vs2005 使用技巧(转)
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429445.html
Copyright © 2011-2022 走看看