varnishi配置

#定义后端主机
backend xueui {
    #.host = "128.199.245.40";
    #.port = "80";
    .host = "xxx.xxx.xxx.xxx";
    .port = "80";
    .connect_timeout = 600s;
    .first_byte_timeout = 600s;
    .between_bytes_timeout = 600s;
}
backend app_xueui {
    .host = "xxx.xxx.xxx.xxx";
    .port = "80";
    .connect_timeout = 600s;
    .first_byte_timeout = 600s;
    .between_bytes_timeout = 600s;
}
backend blog_0550go {
    .host = "127.0.0.1";
    .port = "8080";
    .connect_timeout = 600s;
    .first_byte_timeout = 600s;
    .between_bytes_timeout = 600s;
}
backend bbs_0550buy {
    .host = "127.0.0.1";
    .port = "8080";
    .connect_timeout = 600s;
    .first_byte_timeout = 600s;
    .between_bytes_timeout = 600s;
}

#定义负载均衡(这里没有用到不作配置)
#director lb_test random {
#    {
#      .backend = test1;
#      .weight = 5;
#     }
#     {
#       .backend = test2;
#       .weight = 5;
#     }
#}
#定义清除缓存的权限列表
acl purge {
    "localhost";
    "127.0.0.1";
#    "192.168.100.0"/24;
#    "192.168.0.0"/24;
}

#cl_recv函数 用于接受和处理请求,当请求到达成功接收后被调用,通过判断请求的数据来决定如何处理申请
sub vcl_recv {

#对www.shencan.net域名进行缓存加速

  if (req.http.host ~ "^www.xueui.cn"){
#      set req.http.host = "www.xueui.cn";
      set req.backend = xueui;
  }else
  if (req.http.host ~"^app.xueui.cn"){
#      set req.http.host = "app.xueui.cn";
      set req.backend = app_xueui;
  }else
  if (req.http.host ~"^blog.0550go.com"){
#     set req.http.host = "blog.0550go.com";
      set req.backend = blog_0550go;
  }else
  if (req.http.host ~"^bbs.0550buy.com"){
#      set req.http.host = "bbs.0550buy.com";
      set req.backend = bbs_0550buy;
  }else
  {
    error 408 "Hostname not found";
  }
#如果为purge请求,客户端ip不在访问列表中,返回405拒绝
  if (req.request == "PURGE") {
     if (!client.ip ~purge) {
       error 405 "Not Allowed";
   }

#本地缓存查找
   return(lookup);
  }
#如果为GET请求,url后缀为jpg,png,gif等 取出cookie
  if (req.request == "GET"&&req.url ~ ".(html|txt|jpg|png|gif|swf|jpeg|ico|css|mp3|mp4|htm)$") {
        unset req.http.cookie;
  }

  if (req.request == "GET" && req.url ~ "^/(tutorials|experience|appreciate|download|ui-tutorial-collection|resume-instruction|category/start|category/index|category/userguide|category/login|category/userprofiles|category/nav|category/图片展示|category/table|category/comment|category/searchbar|category/download|category/details-page|category/feedback|category/settings|category/data|category/about|category/other|game-heng)") {
        unset req.http.cookie;
  }
#如果GET请求,url为php,则穿过cache,不缓存
  if (req.request =="GET"&&req.url ~ "(?i).php($|?)"){
        return (pass);
  }
#获取客户端ip
#   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") {
        /* Non-RFC2616 or CONNECT which is weird. */
        return (pipe);
    }
#不是GET 和HEAD及验证请求不缓存
    if (req.request != "GET" && req.request != "HEAD") {
        /* We only deal with GET and HEAD by default */
        return (pass);
    }
    if (req.http.Authorization) {
        /* Not cacheable by default */
        return (pass);
    }
    return (lookup);
 }

#下面这部分是pipe函数体
#此函数在进入pipe模式时被调用,用于将请求直接传递至后端主机,在请求
#返回的内容没有改变的情况下,将不变的内容返回给客户端,直到这个链接
#关闭。
sub vcl_pipe {
     return (pipe);
 }

#vcl_pass
#此函数在进入pass模式时被调用,用于将请求直接传递至后端主机,后端主机
#应答数据后送给客户端,但不进行任何缓存,在当前连接下每次都返回最新的
#内容

sub vcl_pass {
    return (pass);
}
#使用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_miss {
    return (fetch);
}

#vcl_fetch函数
#在从后端主机更新缓存并且获取内容后调用该方法,接着,通过判断获取的内容来
#决定是否将内容放入缓存,还是直接返回给客户端。

sub vcl_fetch {
    if (req.url ~ "html$") {
    set beresp.ttl = 60m;
    set beresp.do_gzip = true;
    unset beresp.http.Cache-Control;
    unset beresp.http.Pragma;
    set beresp.http.Cache-Control = "max-age=3600";
    unset beresp.http.Expires;
   }
    if (req.url ~ "^/(tutorials|experience|appreciate|download|ui-tutorial-collection|resume-instruction|category/start|category/index|category/userguide|category/login|category/userprofiles|category/nav|category/图片展示|category/table|category/comment|category/searchbar|category/download|category/details-page|category/feedback|category/settings|category/data|category/about|category/other|game-heng)") {
    set beresp.ttl = 60m;
    set beresp.do_gzip = true;
    unset beresp.http.Cache-Control;
    unset beresp.http.Pragma;
    set beresp.http.Cache-Control = "max-age=3600";
    unset beresp.http.Expires;
   }
    if (req.request == "GET" && req.url ~ ".(html|txt|jpg|png|gif|swf|jpeg|ico|css|mp3|mp4|htm)$") {
    set beresp.ttl = 36000s;
   }
    return (deliver);
}
# 设置返回状态
sub vcl_deliver {
     set resp.http.x-hits = obj.hits;
     if (obj.hits > 0) {
      set resp.http.X-Cache = "Hit xueui.cn";
   }else {
       set resp.http.X-Cache = "Miss xueui.cn";
   }
     set resp.http.Server = "jack";
     return (deliver);
 }
# 定义错误
sub vcl_error {
     set obj.http.Content-Type = "text/html; charset=utf-8";
     set obj.http.Retry-After = "5";
     synthetic {"
 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html>
   <head>
     <title>"} + obj.status + " " + obj.response + {"</title>
   </head>
   <body>
     <h1>Error "} + obj.status + " " + obj.response + {"</h1>
     <p>"} + obj.response + {"</p>
     <h3>Guru Meditation:</h3>
     <p>XID: "} + req.xid + {"</p>
     <hr>
     <p>Varnish cache server</p>
   </body>
 </html>
 "};
     return (deliver);
}

sub vcl_init {
       return (ok);
}

 sub vcl_fini {
       return (ok);
}
时间: 2024-11-05 06:30:36

varnishi配置的相关文章

Win10下IIS配置、项目发布、添加网站

Win10下IIS配置 1.找到控制面板:[开始]菜单鼠标右击,打开[控制面板] 2.打开控制面板,点击[程序],点击[启用或关闭Windows功能] 下一步,点击[启用虎关闭Windows功能] 3. 开始修改IIS了,我是这样勾上的,有可能比较多. 4. 验证IIS是否正确安装,等待几分钟后IIS配置完成.在浏览器输入http://localhost/iisstart.htm会出现 IIS安装成功页面.第一次修改的时候出现了成功页面,但是后来删除了IIS中默认的网站就打不开了,但是不影响的.

linux下Nginx配置文件(nginx.conf)配置设置详解(windows用phpstudy集成)

linux备份nginx.conf文件举例: cp /usr/local/nginx/nginx.conf /usr/local/nginx/nginx.conf-20171111(日期) 在进程列表里 面找master进程,它的编号就是主进程号. ps -ef | grep nginx 查看进程 cat /usr/local/nginx/nginx.pid 每次修改完nginx文件都要重新加载配置文件linux命令: /usr/local/nginx -t //验证配置文件是否合法 若ngin

solr分布式索引【实战一、分片配置读取:工具类configUtil.java,读取配置代码片段,配置实例】

1 private static Properties prop = new Properties(); 2 3 private static String confFilePath = "conf" + File.separator + "config.properties";// 配置文件目录 4 static { 5 // 加载properties 6 InputStream is = null; 7 InputStreamReader isr = null;

IDEA 配置maven

编写Maven的settings.xml文件内容如下 引入阿里镜像和maven在中国的中央仓库镜像 <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:sc

华为交换机配置telnet和SSH登录设备(简单实用版)

Telnet是Internet远程登陆服务的标准协议和主要方式.它为用户提供了在本地计算机上完成远程主机工作的能力.在终端使用者的电脑上使用telnet程序,用它连接到服务器.终端使用者可以在telnet程序中输入命令,这些命令会在服务器上运行,就像直接在服务器的控制台上输入一样.可以在本地就能控制服务器.要开始一个telnet会话,必须输入用户名和密码来登录服务器.Telnet是常用的远程控制Web服务器的方法,极大的提高了用户操作的灵活性. 测试拓扑图 配置telnet: 1.1普通认证登录

win7设置固定IP重启后无法上网,ipconfig显示为自动配置IPV4 169.254的地址

近日安装原版Win7系统打完网卡驱动补丁后,给电脑设置了固定的IP地址后一切正常,但是电脑重启后发现上不了网了,右下角网络图标有个感叹号,打开网络和共享中心-->本地连接-->详细信息-->发现IPv4的地址与ipconfig /all得到的IP地址一致,均显示为:自动配置IPv4地址:169.254.123.188(首选) 但是查看本地连接-->属性里看到之前设置的固定IP地址是没有问题的, 所以想到了应该是电脑启用了自动配置IPv4功能,导致了固定IP无法分配给电脑, 尝试用命

PL/SQL配置大小写转换等快捷键

Tools(工具) --> Preferences(首选项) --> Key Configuration(键配置) 然后修改自己需要的快捷键方式 作者:itmyhome

联想X270——正版Win10换win7之BIOS配置及系统安装

笔记本安装系统现在是越来越困难了,最早的万能大法Legacy+IDE+win7纯净版光盘的方法已经越来越不适应. 公司新配了出差笔记本联想X270,不再有可刻录光驱,印象当中ThinkPad必定有Thinkvantage,这代也没用了,标配固态硬盘+机械硬盘可以让系统开机速度达到8秒,Fn的组合键在Win10中也运用的流畅自如,内外双电池的配备使得你即便拔了可拆卸电池也不会关机. 即便是这样,还是得到需求,要求安装成Win 7. 下面分享一下我的安装过程. 我这个版本的X270的CPU是6代i5

ubuntu配置静态路由及重启生效

ubuntu配置静态路由及重启生效 第一种方法:使用route命令(添加临时路由) 添加到主机的路由 # route add -host 192.168.1.123 dev eth0 # route add -host 192.168.1.123 gw 192.168.1.1 添加到网络的路由 # route add -net 192.168.1.123 netmask 255.255.255.0 eth0 # route add -net 192.168.1.123 netmask 255.2