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

CentOS系统安装配置varnish服务器

采用redhat,rpm安装方式。rpm--nosignature-ihttp://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpmyuminstallvarnish配置文件在/etc/varnis
采用redhat,rpm安装方式。
rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm
yum install varnish
配置文件在 /etc/varnish/default.vcl 和 /etc/sysconfig/varnish
以下为我的配置文件。
# This is a basic VCL configuration file for varnish.  See the vcl(7)
# man page for details on VCL syntax and semantics.
# Default backend definition.  Set this to point to your content
# server.
backend webserver1 {
 .host = “8.8.8.8″;
 .port = “81″;
 .probe = {
         .url = “/”;
         .interval = 5s;
         .timeout = 5 s;
         .window = 10;
         .threshold = 8;
    }
}
backend webserver2 {
 .host = “8.8.8.8″;
 .port = “83″;
 .probe = {
         .url = “/”;
         .interval = 5s;
         .timeout = 5 s;
         .window = 10;
         .threshold = 8;
    }
}
#director webserver round-robin {
# { .backend = webserver1; }
# { .backend = webserver2; }
#}
director webserver random {
        .retries = 6;
{
        .backend = webserver1;
        .weight = 2;
}
{
        .backend = webserver2;
        .weight = 2;
}
}
#director webserver random {
#    { .backend = www; .weight = 2; }
#    { .backend = { .host = “www2.example.com”; .port = “http”; } .weight = 1; }
#}
acl purge {
        “localhost”;
        “127.0.0.1″;
}
# Below is a commented-out copy of the default VCL logic.  If you
# redefine any of these subroutines, the built-in logic will be
# appended to your code.
 sub vcl_recv {
  # Only cache the following site
# if (req.http.host ~ “(app.iamle.com)”) {
#   set req.backend = webserver;
#  } else {
#   return (pass);
#  }
  if (req.http.host ~ “^(.*?)iamle.com$”) {
        set req.backend = webserver;
    }
  else {
error 404 “Unknown HostName!”;
  }
  if (req.request == “PURGE”) {
if (!client.ip ~ purge) {
error 405 “Not allowed.”;
}
return (lookup);
        }
     if (req.request ==”GET”&&req.url ~ “(?i)\.php($|\?)”){
        return (pass);
     }
 if (req.request == “GET” && req.url ~ “\.(js|css|jpg|png|gif|swf|flv|ico|jpeg|htm|html)$”) {
  unset req.http.COOKIE;
 }
#    if (req.url ~ “^/[^?]+\.(jpeg|jpg|png|gif|ico|js|css|swf|flv|htm|html|shtm)(\?.*|)$”) {
#      unset req.http.COOKIE;
#       set req.url = regsub(req.url, “\?.*$”, “”);
#    }
  if (req.url ~ “^/$”) {
       unset req.http.COOKIE;
    }
#    if (req.request ==”GET”&&req.url ~ “(?i)\.shtml($|\?)”){
#       unset req.http.COOKIE;
#   }
     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;
  }
     }
     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);
     }
     if (req.request != “GET” && req.request != “HEAD”) {
         /* We only deal with GET and HEAD by default */
         return (pass);
     }
#     if (req.http.Authorization || req.http.COOKIE ~ “wordpress_logged” || req.http.COOKIE ~ “comment_”) {
#         /* Not cacheable by default */
#         return (pass);
#     }
# nocache authorization
#     if (req.http.Authorization) {
#         return (pass);
#     }
     if (req.http.Authorization || req.http.COOKIE) {
         return (pass);
     }
     return (lookup);
}
 
 sub vcl_pipe {
     # Note that only the first request to the backend will have
     # X-Forwarded-For set.  If you use X-Forwarded-For and want to
     # have it set for all requests, make sure to have:
     # set bereq.http.cOnnection= “close”;
     # here.  It is not set by default as it might break some broken web
     # applications, like IIS with NTLM authentication.
     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_hit {
 if (req.request == “PURGE”) {
purge;
error 200 “Purged.”;
        }
     return (deliver);
 }
 sub vcl_miss {
 if (req.request == “PURGE”) {
purge;
error 200 “Purged.”;
        }
     return (fetch);
 }
 sub vcl_fetch {
 if (req.url ~ “^/$”) {
  unset beresp.http.set-COOKIE;
  set beresp.ttl = 10m;
  set beresp.do_gzip = true;
  unset beresp.http.Cache-Control;
  unset beresp.http.Pragma;
  set beresp.http.Cache-COntrol= “max-age=600″;
  unset beresp.http.Expires;
     }
#    if (req.request ==”GET”&&req.url ~ “(?i)\.shtml($|\?)”){
#    unset beresp.http.set-COOKIE;
#       set beresp.ttl = 10m;
#    set beresp.do_gzip = true;
#     unset beresp.http.Cache-Control;
#    unset beresp.http.Pragma;
#    set beresp.http.Cache-COntrol= “max-age=600″;
#    unset beresp.http.Expires;
#    }    
     if (beresp.ttl <= 0s ||
beresp.http.Set-COOKIE ||
         beresp.http.Vary == “*”) {
   /*
    * Mark as “Hit-For-Pass” for the next 2 minutes
    */
   set beresp.ttl = 120 s;
   return (hit_for_pass);
     }
#    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 ~ “\.(jpg|png|gif|swf|flv|ico|jpeg)$”) {
        set beresp.ttl = 3h;
     }
#     if (req.request == “GET” && req.url ~ “\.(htm|html|shtml)$”) {
#        set beresp.ttl = 1h;
#     }
 set beresp.ttl = 1h;
     return (deliver);
 }
 
 sub vcl_deliver {
 set resp.http.x-hits = obj.hits;   
 if (obj.hits > 0) {
  set resp.http.X-Cache = “cached”;
 } else {
  set resp.http.x-Cache = “uncached”;
   }
# Remove some headers: PHP version
 unset resp.http.X-Powered-By;  
# Remove some headers: Apache version & OS
 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 {”
 
 
 
   
     
   
   
     Error “} + obj.status + ” ” + obj.response + {“
     

”} + obj.response + {“

Guru Meditation:

XID: “} + req.xid + {“


www.iamle.com cache server

”}; return (deliver); } sub vcl_init { return (ok); } sub vcl_fini { return (ok); }


推荐阅读
  • 本文介绍了如何利用jQuery实现对网页上多个div元素的显示与隐藏控制,包括基本的toggle方法及更复杂的显示隐藏逻辑。 ... [详细]
  • 本文探讨了程序员这一职业的本质,认为他们是专注于问题解决的专业人士。文章深入分析了他们的日常工作状态、个人品质以及面对挑战时的态度,强调了编程不仅是一项技术活动,更是个人成长和精神修炼的过程。 ... [详细]
  • 在1995年,Simon Plouffe 发现了一种特殊的求和方法来表示某些常数。两年后,Bailey 和 Borwein 在他们的论文中发表了这一发现,这种方法被命名为 Bailey-Borwein-Plouffe (BBP) 公式。该问题要求计算圆周率 π 的第 n 个十六进制数字。 ... [详细]
  • CSS Border 属性:solid 边框的使用详解
    本文详细介绍了如何在CSS中使用solid边框属性,包括其基本语法、应用场景及高级技巧,适合初学者和进阶用户参考。 ... [详细]
  • 本文介绍了SIP(Session Initiation Protocol,会话发起协议)的基本概念、功能、消息格式及其实现机制。SIP是一种在IP网络上用于建立、管理和终止多媒体通信会话的应用层协议。 ... [详细]
  • 二维码的实现与应用
    本文介绍了二维码的基本概念、分类及其优缺点,并详细描述了如何使用Java编程语言结合第三方库(如ZXing和qrcode.jar)来实现二维码的生成与解析。 ... [详细]
  • 在日常生活中,支付宝已成为不可或缺的支付工具之一。本文将详细介绍如何通过支付宝实现免费提现,帮助用户更好地管理个人财务,避免不必要的手续费支出。 ... [详细]
  • 本文详细介绍了在Windows系统中如何配置Nginx以实现高效的缓存加速功能,包括关键的配置文件设置和示例代码。 ... [详细]
  • 本文详细介绍了JQuery Mobile框架中特有的事件和方法,帮助开发者更好地理解和应用这些特性,提升移动Web开发的效率。 ... [详细]
  • 我的读书清单(持续更新)201705311.《一千零一夜》2006(四五年级)2.《中华上下五千年》2008(初一)3.《鲁滨孙漂流记》2008(初二)4.《钢铁是怎样炼成的》20 ... [详细]
  • 本文介绍了如何通过C#语言调用动态链接库(DLL)中的函数来实现IC卡的基本操作,包括初始化设备、设置密码模式、获取设备状态等,并详细展示了将TextBox中的数据写入IC卡的具体实现方法。 ... [详细]
  • 数据类型--char一、char1.1char占用2个字节char取值范围:【0~65535】char采用unicode编码方式char类型的字面量用单引号括起来char可以存储一 ... [详细]
  • 本文详细介绍了iOS应用的生命周期,包括各个状态及其转换过程中的关键方法调用。 ... [详细]
  • 探索AI智能机器人自动盈利系统的构建
    用户可通过支付198元押金及30元设备维护费租赁AI智能机器人,推荐他人加入可获得相应佣金。随着推荐人数的增加,用户将逐步解锁更高版本,享受更多收益。 ... [详细]
  • 本文将从基础概念入手,详细探讨SpringMVC框架中DispatcherServlet如何通过HandlerMapping进行请求分发,以及其背后的源码实现细节。 ... [详细]
author-avatar
god
快出去找工作了,加油!!!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有