我们通过负载平衡的 Amazon AWS 环境为多个 Typo3 网站使用 Varnish 3.0.2 前端缓存。一切正常,但使用 POST 方法提交信息的联系表单无法按预期工作。我填写表格并按下提交,浏览器开始运行,但返回表格并保留我输入的信息。如果我在后端 PHP Web 服务器上做同样的事情,那么对于 Post 来说一切正常。所以我认为我的 default.vcl 存在一些问题。我希望这里有一些 Varnish 专家,他们可以帮助 Varnish 新手。
backend default{
.host = "10.0.0.10";
.port = "80";
}
acl ClearCache {
"localhost";
"10.0.0.10";
"10.0.0.96";
}
#acl purge {
# "localhost";
# "10.0.0.96";
#}
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;
}
set req.backend = default;
if (req.request == "POST") {
ban("req.url == " + req.url);
set req.http.X-Test = req.url;
return (pass);
}
if (req.request == "BAN") {
if (!client.ip ~ ClearCache) {
error 405 "Not allowed.";
}
# This option is to clear any cached object containing the req.url
ban("req.url ~ "+req.url);
# This option is to clear any cached object matches the exact req.url
# ban("req.url == "+req.url);
# This option is to clear any cached object containing the req.url
# AND matching the hostname.
# ban("req.url ~ "+req.url+" && req.http.host == "+req.http.host);
error 200 "Cached Cleared Successfully.";
}
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
return (pass);
}
if(req.http.host ~ "typo3.lygie.de"){
##TYPO3-Backend nicht cachen
if (req.http.cookie ~ "be_typo_user"){
##Inhalten löschen wenn Shift+reload gedrückt wird, aber nur bei eingeloggtem user (Backend-Cookie)
if (req.http.Cache-Control ~ "no-cache") {
set req.ttl = 0s;
ban("req.url == " + req.url);
return (pass);
}
}
else{
##Cookies von TYPO3-Seiten löschen
unset req.http.Cookie;
}
}
return (lookup);
}
sub vcl_fetch {
set beresp.ttl = 12h;
set req.grace = 24h;
if (req.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|txt|gz|zip|rar|bz2|tgz|tbz|html|htm|pdf|pls|torrent)$") {
set beresp.ttl = 48h;
}
if (req.url ~ "/typo3") {
}else {
unset beresp.http.set-cookie;
}
return (deliver);
}