您的位置:首页 > Web前端

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

2012-09-29 10:09 447 查看

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

鉴于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 – 基本篇
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: