2014-02-06 56 views
1

有没有人有任何想法我可以绕过Joomfish需要cookie来设置和保留一个joomla网站的语言。服务器端缓存Joomfish(清漆)

我必须使用服务器端缓存为我继承的网站,因为它的构建方式是愚蠢的缓慢和服务器密集型。我无法对它进行重组,因为这将导致重建。

问题是JoomFish设置了一个cookie来确定用户的语言。该cookie被缓存或取消设置。这意味着用户只能获得chached语言网站而不是他们选择的语言。

我正在使用Varnish 3进行服务器端缓存。的Joomla 2.5和2.5.1 Joomfish

我VCL是:

backend default { 
    .host = "127.0.0.1"; 
    .port = "8080"; 
} 
acl purge { 
    "127.0.0.1"; 
    "192.168.0.0"/24; 
} 

sub vcl_recv { 

    # Set up purging cache 
    if(req.request == "PURGE") { 
     if (!client.ip ~ purge) { 
      error 405 "Method not allowed"; 
     } 
     return (lookup); 
    } 

    # Forward client's IP to backend 
    remove req.http.X-Forwarded-For; 
    set req.http.X-Forwarded-For = client.ip; 

    # Proxy (pass) any request that goes to the backend admin, 
    # the banner component links or any post requests 
    # You can add more pages or entire URL structure in the end of the "if" 

    if(req.http.cookie ~ "userID" || req.url ~ "^/administrator" || req.url ~ "^/component/banners" || req.request == "POST") { 
     return (pipe); 
    } 

    # Check for the custom "x-logged-in" header to identify if the visitor is a guest, 
    # then unset any cookie (including session cookies) provided it's not a POST request 
    if(req.http.x-logged-in == "False" && req.request != "POST"){ 
     unset req.http.cookie; 
    } 

    # Properly handle different encoding types 
    if (req.http.Accept-Encoding) { 
     if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") { 
      # No point in compressing these 
      remove req.http.Accept-Encoding; 
     } elsif (req.http.Accept-Encoding ~ "gzip") { 
      set req.http.Accept-Encoding = "gzip"; 
     } elsif (req.http.Accept-Encoding ~ "deflate") { 
      set req.http.Accept-Encoding = "deflate"; 
     } else { 
      # unknown algorithm (aka crappy browser) 
      remove req.http.Accept-Encoding; 
     } 
    } 

    # Cache files with these extensions 
    if (req.url ~ "\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") { 
     return (lookup); 
    } 

    # Set how long Varnish will cache content depending on whether your backend is healthy or not 
    if (req.backend.healthy) { 
     set req.grace = 5m; 
    } else { 
     set req.grace = 1h; 
    } 

    return (lookup); 
} 

sub vcl_fetch { 

    # Check for the custom "x-logged-in" header to identify if the visitor is a guest, 
    # then unset any cookie (including session cookies) provided it's not a POST request 
    if(req.request != "POST" && beresp.http.x-logged-in == "False") { 
     unset beresp.http.Set-Cookie; 
    } 

    # Allow items to be stale if needed (this value should be the same as with "set req.grace" 
    # inside the sub vcl_recv {…} block (the 2nd part of the if/else statement) 
    set beresp.grace = 1h; 

    # Serve pages from the cache should we get a sudden error and re-check in one minute 
    if (beresp.status == 503 || beresp.status == 502 || beresp.status == 501 || beresp.status == 500) { 
     set beresp.grace = 60s; 
     return (restart); 
    } 

    # Unset the "etag" header (suggested) 
    unset beresp.http.etag; 

    # This is Joomla! specific: fix stupid "no-cache" header sent by Joomla! even 
    # when caching is on - make sure to replace 300 with the number of seconds that 
    # you want the browser to cache content 
    if(beresp.http.Cache-Control == "no-cache" || beresp.http.Cache-Control == ""){ 
     set beresp.http.Cache-Control = "max-age=300, public, must-revalidate"; 
    } 

    # This is how long Varnish will cache content 
    set beresp.ttl = 15m; 

    return (deliver); 
} 

sub vcl_hit { 
    if (req.request == "PURGE") { 
     purge; 
     error 200 "Purged"; 
    } 
} 

sub vcl_miss { 
    if (req.request == "PURGE") { 
     purge; 
     error 404 "Not in cache"; 
    } 
} 
sub vcl_pass { 
    if (req.request == "PURGE") { 
     error 502 "PURGE on a passed object"; 
    } 
} 
+0

您的VCL的外观如何? –

+0

根据要求添加上面 – DavidT

回答

1

现在我已经想通了这一点。对于任何其他人遇到同样的问题。您可以简单地传递给服务器上的joomfish cookie的值。例如:

sub vcl_recv { 
    if(req.http.cookie ~ "jfcookie\[lang\]=fr"){ 
     return (pass); 
    } 
} 

这将确保法国用户收到法国网站。尽管如此,还没有想出一种方法来分别缓存法国网站。显然你可以用哈希做一些事情。我现在正在研究的是哪一个,如果找到解决方案就会发布解决方案。