Я пытаюсь настроить лак для учетной записи языкового fileа cookie

Я довольно новичок в мире кешлаков, и мне нужно оптимизировать приложение WordPress, которое довольно медленно. Сегодня я провел много исследований, и я сделал некоторый прогресс, но я застрял в настройке для языковых куки.

Таким образом, приложение устанавливает куки-file под названием qtrans_front_language который указывает, какой язык должен использоваться interfaceом. Я хочу кэшировать все страницы с помощью лака, но я не могу игнорировать этот file cookie, иначе я не могу переkeyиться на язык после кэширования страницы, и я получаю странное поведение при навигации из разных browserов одновременно.
Я думал о добавлении определения языка (например, «en») к hashу при кешировании, чтобы каждая страница получала свою собственную запись в кеше, а в следующий раз, когда я ее просматриваю, я получаю HIT.

Моя проблема заkeyается в том, что этот file cookie установлен бэкэнд, но, если я не «отбрасываю» бэкэнд-fileы cookie, мои страницы никогда не кэшируются лаком.

Это то, что у меня есть до сих пор:

 vcl 4.0; # Import directors and std library. import directors; import std; # Backend backend default { .host = "my_ip_here"; .port = "80"; .connect_timeout = 600s; .first_byte_timeout = 600s; .between_bytes_timeout = 600s; .max_connections = 800; .probe = { .url = "/"; .timeout = 1s; .interval = 5s; .window = 5; .threshold = 3; } } sub vcl_init { new foo = directors.round_robin(); foo.add_backend(default); } sub vcl_recv { call identify_cookie; # Send all traffic to the foo director. set req.backend_hint = foo.backend(); # Skip administrative areas if (req.url ~ "wp-admin|wp-login|xmlrpc.php") { return(pass); } # Do not cache POST requests. if (req.http.Authorization || req.method == "POST") { return(pass); } # Remove all cookies that starts with '__', namely Google Analytics cookies. set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[az]+|has_js)=[^;]*", ""); # Remove language cookie. set req.http.Cookie = regsuball(req.http.Cookie, "qtrans_front_language=.*", ""); # Remove wordpress cookies. set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-1=[^;]+(; )?", ""); set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-time-1=[^;]+(; )?", ""); set req.http.Cookie = regsuball(req.http.Cookie, "wordpress_test_cookie=[^;]+(; )?", ""); # Remove empty cookies set req.http.Cookie = regsuball(req.http.Cookie, "^ *$", ""); set req.http.Cookie = regsuball(req.http.Cookie, "^; +?$", ""); # Cache images, css, js and other static content. if (req.url ~ "\.(css|js|png|gif|jp(e)?g|swf|ico)") { unset req.http.cookie; call normalize_req_url; } # Normalize Accept-Encoding header and compression if (req.http.Accept-Encoding) { # Do not compress compressed files. if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") { unset 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 { unset req.http.Accept-Encoding; } } if (req.http.Cookie == "") { unset req.http.Cookie; } return(hash); } sub vcl_backend_response { # Set a grace time of 1h set beresp.grace = 1h; # Set a TTL of 10m set beresp.ttl = 10m; # Avoid setting cookies and Cache-Control if url !~ wp-(login|admin) if (!bereq.url ~ "wp-(login|admin)") { unset beresp.http.Set-Cookie; unset beresp.http.Cache-Control; } } sub vcl_hash { hash_data(req.url); if (req.http.host) { hash_data(req.http.host); } else { hash_data(server.ip); } if (!req.http.Language) { set req.http.Language = "en"; } hash_data(req.http.Language); # If the client supports compression, keep that in a different cache entry if (req.http.Accept-Encoding) { hash_data(req.http.Accept-Encoding); } return (lookup); } sub vcl_deliver { # A bit of debugging info. if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; } } sub vcl_hit { # A cache hit, deliver it. if (obj.ttl >= 0s) { return(deliver); } # If object is in grace deliver it and trigger a background fetch. # Also make sure backend is healthy. if (!std.healthy(req.backend_hint) && (obj.ttl + obj.grace > 0s)) { return(deliver); } else { return(fetch); } } # This method is used to strip out ?timestamp=[0-9]+ from the url # so that we can hash it later. sub normalize_req_url { if (req.url ~ "\?timestamp=[0-9]+") { set req.url = regsuball(req.url, "\?timestamp=[0-9]+", ""); } } sub identify_cookie { if (req.http.cookie ~ "qtrans_front_language=") { set req.http.Language = regsub(req.http.Cookie, "(.*?)(qtrans_front_language=)([^;]*)(.*)$", "\3"); } } по vcl 4.0; # Import directors and std library. import directors; import std; # Backend backend default { .host = "my_ip_here"; .port = "80"; .connect_timeout = 600s; .first_byte_timeout = 600s; .between_bytes_timeout = 600s; .max_connections = 800; .probe = { .url = "/"; .timeout = 1s; .interval = 5s; .window = 5; .threshold = 3; } } sub vcl_init { new foo = directors.round_robin(); foo.add_backend(default); } sub vcl_recv { call identify_cookie; # Send all traffic to the foo director. set req.backend_hint = foo.backend(); # Skip administrative areas if (req.url ~ "wp-admin|wp-login|xmlrpc.php") { return(pass); } # Do not cache POST requests. if (req.http.Authorization || req.method == "POST") { return(pass); } # Remove all cookies that starts with '__', namely Google Analytics cookies. set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[az]+|has_js)=[^;]*", ""); # Remove language cookie. set req.http.Cookie = regsuball(req.http.Cookie, "qtrans_front_language=.*", ""); # Remove wordpress cookies. set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-1=[^;]+(; )?", ""); set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-time-1=[^;]+(; )?", ""); set req.http.Cookie = regsuball(req.http.Cookie, "wordpress_test_cookie=[^;]+(; )?", ""); # Remove empty cookies set req.http.Cookie = regsuball(req.http.Cookie, "^ *$", ""); set req.http.Cookie = regsuball(req.http.Cookie, "^; +?$", ""); # Cache images, css, js and other static content. if (req.url ~ "\.(css|js|png|gif|jp(e)?g|swf|ico)") { unset req.http.cookie; call normalize_req_url; } # Normalize Accept-Encoding header and compression if (req.http.Accept-Encoding) { # Do not compress compressed files. if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") { unset 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 { unset req.http.Accept-Encoding; } } if (req.http.Cookie == "") { unset req.http.Cookie; } return(hash); } sub vcl_backend_response { # Set a grace time of 1h set beresp.grace = 1h; # Set a TTL of 10m set beresp.ttl = 10m; # Avoid setting cookies and Cache-Control if url !~ wp-(login|admin) if (!bereq.url ~ "wp-(login|admin)") { unset beresp.http.Set-Cookie; unset beresp.http.Cache-Control; } } sub vcl_hash { hash_data(req.url); if (req.http.host) { hash_data(req.http.host); } else { hash_data(server.ip); } if (!req.http.Language) { set req.http.Language = "en"; } hash_data(req.http.Language); # If the client supports compression, keep that in a different cache entry if (req.http.Accept-Encoding) { hash_data(req.http.Accept-Encoding); } return (lookup); } sub vcl_deliver { # A bit of debugging info. if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; } } sub vcl_hit { # A cache hit, deliver it. if (obj.ttl >= 0s) { return(deliver); } # If object is in grace deliver it and trigger a background fetch. # Also make sure backend is healthy. if (!std.healthy(req.backend_hint) && (obj.ttl + obj.grace > 0s)) { return(deliver); } else { return(fetch); } } # This method is used to strip out ?timestamp=[0-9]+ from the url # so that we can hash it later. sub normalize_req_url { if (req.url ~ "\?timestamp=[0-9]+") { set req.url = regsuball(req.url, "\?timestamp=[0-9]+", ""); } } sub identify_cookie { if (req.http.cookie ~ "qtrans_front_language=") { set req.http.Language = regsub(req.http.Cookie, "(.*?)(qtrans_front_language=)([^;]*)(.*)$", "\3"); } } 

Поэтому я могу обнаружить текущий язык, но я делаю что-то неправильно, потому что, даже если user устанавливает другой язык, обслуживается неправильная страница. Я думаю, что beresp.http.Set-Cookie в backend-ответе, вероятно, неправильная вещь.

Что я делаю не так? Как я могу решить эту проблему?

Давайте будем гением компьютера.