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

  • 相关阅读:
    Mysql经常使用函数
    ZOJ 3690 Choosing number
    cocos2d-x 多触点监听
    ansible不配ssh连接,用户密码登录
    Ansible Role
    关闭centos自动升级内核
    让外部网络访问K8S service的四种方式
    Hadoop实战:Hadoop分布式集群部署(一)
    Docker:搭建私有仓库(Registry 2.4)
    Docker下的Spring Cloud三部曲之一:极速体验
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429445.html
Copyright © 2011-2022 走看看