热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

varnish缓存三:VCL配置示例

我公司当前线上varnish配置示例:#backenddefault{#.host127.0.0.1;#.port8080;#}backends360_01{.

我公司当前线上varnish配置示例:

#backend default {

#.host = "127.0.0.1";

#.port = "8080";

#}


backend s360_01 {

.host = "192.168.0.114";

.port = "18286";

.probe = {

       .url = "/";

       .interval = 5s;

       .timeout = 1 s;

       .window = 5;

       .threshold = 3;

}

}


backend s360_02 {

.host = "192.168.0.115";

.port = "18286";

.probe = {

       .url = "/";

       .interval = 5s;

       .timeout = 1 s;

       .window = 5;

       .threshold = 3;

}

}


backend swdj_01 {

.host = "192.168.0.114";

.port = "8092";

.probe = {

       .url = "/";

       .interval = 5s;

       .timeout = 1 s;

       .window = 5;

       .threshold = 3;

}

}


backend swdj_02 {

.host = "192.168.0.115";

.port = "8092";

.probe = {

       .url = "/";

       .interval = 5s;

       .timeout = 1 s;

       .window = 5;

       .threshold = 3;

}

}


backend bf_01 {

.host = "192.168.0.111";

.port = "18282";

.probe = {

       .url = "/";

       .interval = 5s;

       .timeout = 1 s;

       .window = 5;

       .threshold = 3;

}

}


backend bf_02 {

.host = "192.168.0.112";

.port = "18282";

.probe = {

       .url = "/";

       .interval = 5s;

       .timeout = 1 s;

       .window = 5;

       .threshold = 3;

}

}


backend zsoft_01 {

.host = "192.168.0.111";

.port = "8090";

.probe = {

       .url = "/";

       .interval = 5s;

       .timeout = 1 s;

       .window = 5;

       .threshold = 3;

}

}


backend zsoft_02 {

.host = "192.168.0.112";

.port = "8090";

.probe = {

       .url = "/";

       .interval = 5s;

       .timeout = 1 s;

       .window = 5;

       .threshold = 3;

}

}


director s360 random {

{.backend = s360_01; .weight = 5;}

{.backend = s360_02; .weight = 5;}

}


director wdj random {

{.backend = swdj_01; .weight = 5;}

{.backend = swdj_02; .weight = 5;}

}


director bf random {

{.backend = bf_01; .weight = 5;}

{.backend = bf_02; .weight = 5;}

}


director zsoft random {

{.backend = zsoft_01; .weight = 5;}

{.backend = zsoft_02; .weight = 5;}

}


acl local{

"localhost";

"127.0.0.1";

"192.168.0.0"/24;

}


sub vcl_recv {


if(req.url ~ "^/s360/") {

set req.backend = s360;

}else if(req.url ~ "^/swdj/"){

set req.backend = wdj;

}else if(req.url ~ "^/bf/"){

set req.backend = bf;

}else if(req.url ~ "^/zsoft/"){

set req.backend = zsoft;

#}else{

#set req.backend = default.

}


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.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.request != "GET" &&

req.request != "HEAD" &&

req.request != "PUT" &&

req.request != "POST" &&

req.request != "TRACE" &&

req.request != "OPTIONS" &&

req.request != "DELETE") {

       return (pipe);

}

   if (req.request != "GET" && req.request != "HEAD") {

return (pass);

}


if(req.http.Authenticate || req.http.Authorization) {

return (pass);

}


if(req.request == "PURGE"){

if(!client.ip ~ local){

error 405 "Not Allowed.";

}

return (lookup);

}


if(req.request == "GET" && req.url ~ "\.(jpg|png|gif|swf|jpeg|ico|js|mp4|css)$"){

unset req.http.COOKIE;

set req.url = regsub(req.url, "\?.*$", "");

}


set req.grace = 15s;

return (lookup);

}


sub vcl_pipe {

return (pipe);

}


sub vcl_pass {

return (pass);

}


sub vcl_hash {

hash_data(req.url);

if (req.http.host) {

hash_data(req.http.host);

} else {

hash_data(server.ip);

      }

return (hash);

}


sub vcl_miss {

if(req.request == "PURGE") {

error 404 "not in cache.";

}

return (fetch);

}


sub vcl_hit {

if(req.request == "PURGE"){

purge;

error 200 "purged";

}

return (deliver);

}


sub vcl_fetch {


if (beresp.http.Pragma ~"no-cache" ||

beresp.http.Cache-Control ~"no-cache" ||

beresp.http.Cache-Control ~"private") {

return (deliver);

}


if (beresp.status == 404 || beresp.status == 300){

error 404;

}


if (req.request == "GET" && req.url ~ "^/s360(.*)$") {  

   set beresp.ttl = 3600s;  

}


if (req.request == "GET" && req.url ~ "^/swdj(.*)$") {

           set beresp.ttl = 43200s;

       }


if (req.request == "GET" && req.url ~ "^/bf(.*)$") {

           set beresp.ttl = 43200s;

       }


if (req.request == "GET" && req.url ~ "^/zsoft(.*)$") {

           set beresp.ttl = 43200s;

       }


if (req.request == "GET" && req.url ~ ".(html|htm)$"){

set beresp.ttl = 1d;

}


if (req.request == "GET" && req.url ~ "\.(png|xsl|xml|pdf|ppt|doc|docx|chm|rar|zip|bmp|jpeg|swf|ico|mp3|mp4|rmvb|ogg|mov|avi|wmv|swf|txt|png|gif|jpg|css|js|html|htm)$") {  

set beresp.ttl = 7d;  

}


set beresp.grace = 30m;

return(deliver);

}


sub vcl_deliver {

set resp.http.x-hits = obj.hits;

if(obj.hits > 0){

set resp.http.X-Cache = " HIT 360";

}else{

set resp.http.X-Cache = "MISS 360";

}

unset resp.http.X-Powered-By;

unset resp.http.Server;

return (deliver);

}


sub vcl_error {

    set obj.http.Content-Type = "text/html; charset=utf-8";

    set obj.http.Retry-After = "5";

    synthetic {"

 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 

   

 

 

   

Error "} + obj.status + " " + obj.response + {"

   

"} + obj.response + {"

   

Guru Meditation:

   

XID: "} + req.xid + {"

   


   

Varnish cache server

 

"};

    return (deliver);

}


sub vcl_init {

  return (ok);

}


sub vcl_fini {

  return (ok);

}


本文出自 “无名小卒” 博客,请务必保留此出处http://breezey.blog.51cto.com/2400275/1339435


推荐阅读
  • varnish2.04配置文章来源:http:blog.163.comkoumm126blogstatic9540383720091182424317修改varnishheader ... [详细]
  • 采用IKE方式建立IPsec安全隧道
    一、【组网和实验环境】按如上的接口ip先作配置,再作ipsec的相关配置,配置文本见文章最后本文实验采用的交换机是H3C模拟器,下载地址如 ... [详细]
  • 目录一、salt-job管理#job存放数据目录#缓存时间设置#Others二、returns模块配置job数据入库#配置returns返回值信息#mysql安全设置#创建模块相关 ... [详细]
  • 深入解析SpringMVC核心组件:DispatcherServlet的工作原理
    本文详细探讨了SpringMVC的核心组件——DispatcherServlet的运作机制,旨在帮助有一定Java和Spring基础的开发人员理解HTTP请求是如何被映射到Controller并执行的。文章将解答以下问题:1. HTTP请求如何映射到Controller;2. Controller是如何被执行的。 ... [详细]
  • 深入解析Spring启动过程
    本文详细介绍了Spring框架的启动流程,帮助开发者理解其内部机制。通过具体示例和代码片段,解释了Bean定义、工厂类、读取器以及条件评估等关键概念,使读者能够更全面地掌握Spring的初始化过程。 ... [详细]
  • 在项目中使用 Redis 时,了解其不同架构模式(如单节点、主从复制、哨兵模式和集群)对于确保系统的高可用性和扩展性至关重要。本文将详细探讨这些模式的特点和应用场景。 ... [详细]
  • 作为140字符的开创者,Twitter看似简单却异常复杂。其简洁之处在于仅用140个字符就能实现信息的高效传播,甚至在多次全球性事件中超越传统媒体的速度。然而,为了支持2亿用户的高效使用,其背后的技术架构和系统设计则极为复杂,涉及高并发处理、数据存储和实时传输等多个技术挑战。 ... [详细]
  • 一句话解决高并发的核心原则
    本文介绍了解决高并发的核心原则,即将用户访问请求尽量往前推,避免访问CDN、静态服务器、动态服务器、数据库和存储,从而实现高性能、高并发、高可扩展的网站架构。同时提到了Google的成功案例,以及适用于千万级别PV站和亿级PV网站的架构层次。 ... [详细]
  • 运维入门
    2019独角兽企业重金招聘Python工程师标准本文内容遵从CC版权协议转载请注明出自oschina.netedwinaclaublog#运维入门一个 ... [详细]
  • EvanWeaver是Twitter服务团队的总工程师,他的主要工作是优化与伸缩性。在QConLondon2009上,他谈到了Twitter的架构&#x ... [详细]
  • Ivearails3app,runningwellfastonherokusbamboostack.Totestwhethermyappworksontheu ... [详细]
  • 分布式系统关注点——360°全方位解读「缓存」
    如果这是第二次看到我的文章,欢迎文末扫码订阅我个人的公众号(跨界架构师)哟~  本文长度为3578字,建议阅读10分钟。坚持原创,每 ... [详细]
  • Varnish搭建CDN内容分发网络
    概述:1.CDN内容分发网络CDN的全称是ContentDeliveryNetwork,即内容分发网络。其基本思路是尽可能避开互联网上有可能影响数据 ... [详细]
  • 深入解析Java虚拟机(JVM)架构与原理
    本文旨在为读者提供对Java虚拟机(JVM)的全面理解,涵盖其主要组成部分、工作原理及其在不同平台上的实现。通过详细探讨JVM的结构和内部机制,帮助开发者更好地掌握Java编程的核心技术。 ... [详细]
  • 远程过程调用(RPC)是一种允许客户端通过网络请求服务器执行特定功能的技术。它简化了分布式系统的交互,使开发者可以像调用本地函数一样调用远程服务,并获得返回结果。本文将深入探讨RPC的工作原理、发展历程及其在现代技术中的应用。 ... [详细]
author-avatar
书友80433968_667
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有