html重定向在使用清漆时被阻止

时间:2012-03-28 19:42:41

标签: node.js redirect varnish express varnish-vcl

我在ubuntu 11上使用varnish 3.0 - 重定向由expressjs处理(v2.5.8 - 运行node.js 0.6) - 重定向由express调用(中间没有清漆)但是当使用varnish时之间,重定向到新页面被阻止(显示'错误302找到')。

在varix的vcl配置文件中,我试图基于URL和Referer(在子vcl_recv部分中)传递(返回)但我似乎配置错​​误(或者需要添加更多配置步骤)。任何有关vcl文件更改的想法/建议都会非常受欢迎,这将允许varnish让expressjs重定向到新页面。

提前致谢。

1 个答案:

答案 0 :(得分:0)

更改sub_vcl_fetch修复它。

我已经从下面的vcl文件中复制了部分sub_vcl_fetch部分:

sub vcl_fetch {

# Do not cache the object if the backend application does not want us to.
if (beresp.http.Cache-Control ~ "(no-cache|no-store|private|must-revalidate)") {
return(pass);
}

# Do not cache the object if the status is not in the 200s
if (beresp.status >= 300) {
# Remove the Set-Cookie header
#remove beresp.http.Set-Cookie;
return(pass);
}

#
# Everything below here should be cached
#
# Remove the Set-Cookie header
####remove beresp.http.Set-Cookie;

# Set the grace time
set beresp.grace = 1s;

# Static assets aren't served out of Varnish just yet, but when they are, this will
# make sure the browser caches them for a long time.
if (req.url ~ "\.(css|js|jpg|jpeg|gif|ico|png)\??\d*$") {
/* Remove Expires from backend, it's not long enough */
unset beresp.http.expires;

/* Set the clients TTL on this object */
set beresp.http.cache-control = "public, max-age=31536000";

/* marker for vcl_deliver to reset Age: */
set beresp.http.magicmarker = "1";} else {
set beresp.http.Cache-Control = "private, max-age=0, must-revalidate";
set beresp.http.Pragma = "no-cache";}

## If the request to the backend returns a code other than 200, restart the loop
## If the number of restarts reaches the value of the parameter max_restarts,
## the request will be error'ed.  max_restarts defaults to 4.  This prevents
## an eternal loop in the event that, e.g., the object does not exist at all.
if (beresp.status != 200 && beresp.status != 403 && beresp.status != 404) {
restart;
}


if (beresp.status == 302) {
return(deliver);}
# return(deliver); the object
return(deliver);
}

希望这有帮助!