![sub vcl_recv | Magento + Varnish](https://linux22.com/image/577690/sub%20vcl_recv%20%7C%20Magento%20%2B%20Varnish.png)
我想请人帮忙。我浏览了很多包含 Varnish 教程和示例 VCL 文件的页面,但找不到任何与为 Magento 配置 Varnish 相关的内容(至少它们不能正常工作)。
我发现的所有手册在启动 Varnish 时都会抛出很多错误,而且它们似乎适用于旧版本。(此外,magento 模块 PageCache 和 Varnish Extension 都不适用于我,因为我认为 Varnish 本身无法正常工作)
我的问题:
1. 我使用 Varnish 来缓存前端,但它破坏了我表单、支付模块、新闻通讯订阅等几乎所有功能。2
. 我发现更改“sub vcl_recv”中的一个单词会改变所有内容。该单词是:return(lookup)。这是我的“sub vcl_recv”的代码:
sub vcl_recv {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
if(server.ip ~ a168_144_38_181){
set req.backend = b168_144_38_181;
}
}
if (req.url ~ "^/images") {
unset req.http.cookie;
}
if (req.url ~ "^(/index.php)?/(admin|customer|checkout|add|product_compare|switch|___store|referer|contact|chat|payone|sendfriend|review|api|NOCACHE|post|robots.txt|j2tajaxcheckout|cron.php|varnish)") {
return(pass);
}
if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
set req.http.user-agent = "Mozilla";
unset req.http.Https;
unset req.http.cookie;
return (lookup);
}
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);
}
#parse accept encoding rulesets to normalize
if (req.http.Accept-Encoding) {
if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
# no need of compression
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
remove req.http.Accept-Encoding;
remove req.http.Cookie;
remove req.http.X-Pass;
set req.grace = 30s;
return (lookup);
}
}
有人能帮我进行设置吗?
任何帮助将不胜感激!!!
谢谢。托马斯
答案1
看起来你的 Varnish 配置错误
基本上,如果请求不是 GET 或 HEAD,你应该将请求传递给后端
if (req.request != "GET" && req.request != "HEAD") {
return (pass);
}
接下来,您应该检查会话管理,如果存在某些 cookie,请将用户传递给后端。无法谈论标准 Magento cookie,尚未使用它