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

  • 相关阅读:
    20160405小结
    [HTML表格]在databases显示行的附加信息
    [django]django+datatable简单运用于表格中
    [django]django xlrd处理xls中日期转换问题
    烦!
    【数据库】Navicat Premium12远程连接MySQL数据库
    关于定义变量名为"name"的坑!!!
    【前端】前端面试题整理
    Firebug控制台详解
    什么是跨域?跨域解决方法
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429445.html
Copyright © 2011-2022 走看看