主頁 > Drupal | 服務器技術 > Varnish前端代理Drupal的配置以及Jenkins

Varnish前端代理Drupal的配置以及Jenkins

PDF版本

鑒于varnish使用以及教程都較少,所以特將Varnish作為drupal的前端代理配置貼出來,供大家參考使用。順便設置了Jenkins的代理轉發,如果要啟動Jenkins,請注意端口號。

Apache/Nginx只需監聽127.0.0.1的80端口即可,Varnish監聽公網IP的80端口,負責轉發請求。
文件中附帶了Round-Robin負載均衡的設置,如果有多個服務器,可以參考之,文件默認位置:/etc/varnish/default.vcl。

backend default {
  .host = "127.0.0.1";
  .port = "80";
}
 
backend jenkins {
  .host = "127.0.0.1";
  .port = "8100";
}
 
##############################
##   Round Robin Backend     #
##############################
#backend rr1 {
#  .host = "192.168.8.1";
#  .port = "80";
#  .probe = { .url = "/ee.txt";
#             .interval = 20 s;
#             .timeout = 10 s;
#             .window = 10;
#             .threshold = 2;
#  }
#}
#backend rr2 {
#  .host  = "192.168.8.2";
#  .port  = "80";
#  .probe = { .url = "/ee.txt";
#             .interval = 20 s;
#             .timeout = 10 s;
#             .window = 10;
#             .threshold = 2;
#  }
#}
#director zcn round-robin {
#  { 
#    .backend = rr1;
#  }
#  { 
#    .backend = rr2;
#  }
#}
##############################
 
# 
# 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 {
 
  #jenkins
  if (req.url ~ "^/jenkins") {
    set req.backend = jenkins;
  }
 
  #if (req.http.host ~ "^domain.com$") {
  # set req.backend = default;
  #}
 
  # Download large files
  if (req.url ~ "\.(csv|pdf|xml|rar|zip)") {
     return(pipe);
  }
  # Prevent cache
  if (req.url ~ "^logout$" || req.url ~ "^/cron.php") {
     return (pass);
  }
 
  # Remove cookies
  set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_gscu_|_gscs_|_gscbrs_|zinch_flag_like|zt|paq_cookietime)[^;]*", "");
  set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
  if (req.http.Cookie ~ "^\s*$") {
    remove req.http.Cookie;
  }
  if (req.url ~ "\.(jpg|png|css|js|ico|gz|tgz|bz2|tbz|gif)$") {
    remove 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) {
    /* Not cacheable by default */
    return (pass);
  }
  return (lookup);
}
 
sub vcl_deliver {
  # Add http header to indicate if cache hit
  if (obj.hits > 0) {
    set resp.http.X-Cache = "HIT";
  } else {
    set resp.http.X-Cache = "MISS";
  }
}

順便公布幾個Varnish常用的技巧命令:

測試VCL

/usr/sbin/varnishd -F -f /etc/varnish/active.vcl -u varnish -g varnish -a :81 -n test_instance -s file,/tmp/varnish_storage.bin,10M

清除所有緩存

ban.url .*

載入新VCL以及使用

vcl.load  load01 /etc/varnish/new.vcl;
vcl.use load01

其他參考文章:
Varnish構建高負載Drupal網站 – 高級篇
高負載網站之Varnish與Drupal – 基本篇


聲明: 本站所有文章歡迎轉載,所有文章未說明,均屬于原創,轉載均請注明出處。
本文有效鏈接: http://www.tbdskt.live/2012/08/drupal-varnish-jenkins/
版權所有: Drupal與高性能網站架構 http://www.tbdskt.live


, ,

評論:2

發表評論
  1. avatar
    回復 jke
    13/12/22

    鄙人關注drupal有3年了,最近才把目標放在了開發上,如何加入貴站的高手圈是鄙人的莫大榮幸

  2. avatar
    回復 robbin
    13/12/23

    如果要發稿的話,你先投稿+個人介紹,通過后,給你開放后臺權限:P
    zhaogaoxin#gmail.com

    Drupal北京QQ群 167936429

發表評論

電子郵件地址不會被公開。 必填項已用 * 標注


+ 六 = 7

您可以使用這些 HTML 標簽和屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

引用:0

下面所列的是引用到本博客的鏈接
Varnish前端代理Drupal的配置以及Jenkins 來自 Drupal與高性能網站架構
頂部
四川时时彩投注平台