简体   繁体   English

同一站点的不同Varnish缓存存储

[英]Different Varnish cache stores for same site

I have a multi lingual joomla site that uses Joomfish for translations. 我有一个使用Joomfish进行翻译的多语言joomla网站。 Due to Joomfish using a cookie to change language and not a different url I have had major issues getting this to work. 由于Joomfish使用Cookie来更改语言,而不是使用其他网址,因此在使其正常工作方面遇到了主要问题。 However I have found a way to get round it by getting varnish to check the cookie value, if english serve cache, if anything else then pass to server. 但是,我找到了一种方法来解决此问题,方法是让清漆检查cookie值,如果英语提供缓存,则将其他任何内容传递给服务器。

Thats great, but I want to be able to cache the other versions. 很好,但是我希望能够缓存其他版本。 Is there a way to serve a different cache to different languages. 有没有一种方法可以为不同的语言提供不同的缓存。 So a cached version of german, french etc. 因此是德语,法语等的缓存版本。

I have tried using different nginx config files and setting different varnish back ends but that didnt seem to work. 我尝试使用不同的nginx配置文件并设置不同的清漆后端,但这似乎没有用。

For that I did: 为此,我做到了:

/* default is english */
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

/* french backend */
backend french {
    .host = "127.0.0.1";
    .port = "8081";
}

Then in my sub recv function: 然后在我的sub recv函数中:

if(req.http.cookie ~ "jfcookie\[lang\]=fr"){
    set req.backend = french;
}

That seems to serve the same cached backend though. 不过,这似乎服务于相同的缓存后端。 So if your on french it sends you to english content. 因此,如果您使用法语,则会将您转至英语。

我相信您可以通过发送variable标头来简单地处理此问题。您可以让您的应用设置标头(例如X-language并发送标头Vary: X-language这样,varnish可以理解共有2种不同的语言并分别缓存。

I have this working now. 我现在正在工作。 For anyone in the same situation, check out hashing. 对于处于相同情况的任何人,请查看哈希。 I have detailed below my solution. 我在下面详细介绍了我的解决方案。

sub vcl_recv {
    if(req.http.cookie ~ "jfcookie\[lang\]=fr"){
        set req.http.X-Cookie-Language = "fr";
    }
}

sub vcl_hash {
    hash_data(req.http.X-Cookie-Language);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM