清漆caching:如果会话处于活动状态,则重写ESI包含URL

我正在寻找重写一个ESI包括在光油url。

在我的模板中,我有:

<esi:include src="/esi/user.html" /> 

其中只包含静态内容,即“欢迎访客”。

如果他们login我将会话添加到我的.vcl。

我想要做的是重写包括:

 <esi:include src="/esi/user.active.html" /> 

在那里我会做数据库查询。

目前,在我的子vcl_recv我有:

 if (req.http.Cookie ~ "SessionId") { if (req.url ~ "^/esi/(.*)\.html") { set req.url = regsub("^/esi/(.*)\.html", "$0", ".active"); } } 

它在前端导致503错误。 我将如何更新这个重写URL并使其工作?

好吧,得到这个工作。 如果有人感兴趣,这是我的.VCL文件

 backend default { .host = "127.0.0.1"; .port = "8080"; } sub vcl_recv { 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); } # Remove cookie for static files if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|woff|ttf|eot|svg)(\?[a-zA-Z0-9\=\.\-]+)?$") { remove req.http.cookie; } # Quick hack for now to clear the cache on post if (req.request == "POST") { ban("req.http.host == "+ req.http.Host); return(pass); } # If CraftSessionId isn't active, remove cookies altogether if (req.http.Cookie) { set req.http.Cookie = ";" + req.http.Cookie; set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";"); set req.http.Cookie = regsuball(req.http.Cookie, ";(CraftSessionId)=", "; \1="); set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", ""); set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", ""); if (req.http.Cookie == "") { remove req.http.Cookie; } } # If user is logged in/has cookies enabled, rewrite esi files to include *.active.html if (req.http.cookie ~ "CraftSessionId=") { if (req.url ~ "^/esi") { set req.url = regsub(req.url, "^/esi/(.*).html", "/esi/\1-active.html"); } } # Grace period for falldown set req.grace = 1h; } sub vcl_fetch { set beresp.ttl = 24h; # Make cache last 24 hours # Allow cookies in admin and account areas if (req.url !~ "(admin/login|account/login|account/register)") { unset beresp.http.set-cookie; } set beresp.do_gzip = true; set beresp.do_esi = true; # Allow ESI # Grace period for falldown set beresp.grace = 1h; }