Integrate Liferay with Varnish will help you to reduce load on Web, Application and Database server drastically which obviously results to improve overall performance. Varnish is one of the popular open source web application accelerators. Liferay + Varnish is a sure shot for enhancing web-site performance.

Varnish server will decide if the request should be served from cache or request should be served from Web/Application server.

Below VCL file is compatible with Varnish 3.0

Code Snippet:

  backend default {
.host = "localhost";
.port = "80";
}
 
sub vcl_recv {
if (req.http.x-forwarded-for) {
remove 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 (!req.backend.healthy) {
unset req.http.Cookie;
 
}
 
if (req.backend.healthy) {
set req.grace = 60s;
} else {
set req.grace = 24h;
}
 
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 == "POST") {
return(pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
return (pass);
}
 
if (req.http.Accept-Encoding) {
if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
remove req.http.Accept-Encoding;
}
elsif (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
}
elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
set req.http.Accept-Encoding = "deflate";
}
} else {
remove req.http.Accept-Encoding;
}
 
if (!req.backend.healthy) {
unset req.http.Cookie;
}
if (req.http.Cookie) {
return (pass);
}
return (lookup);
}
 
sub vcl_pipe {
return (pipe);
}
 
sub vcl_pass {
return (pass);
}
 
sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
return (hash);
}
 
sub vcl_hit {
return (deliver);
}
 
sub vcl_miss {
return (fetch);
}
 
sub vcl_fetch {
if (beresp.status == 404 || beresp.status == 503) {
set beresp.ttl = 0s;
return (hit_for_pass);
}
if (!req.backend.healthy) {
set beresp.ttl = 1h;
unset beresp.http.set-Cookie;
}
if (beresp.http.Set-Cookie) {
return (hit_for_pass);
}
set beresp.grace = 24h;
return (deliver);
}
 
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Varnish-Cache = "HIT";
}
else {
set resp.http.X-Varnish-Cache = "MISS";
}
}
 
sub vcl_init {
return (ok);
}
 
sub vcl_fini {
return (ok);
}
 
sub vcl_error {
return(deliver);
}

Cloud Cost Management Logo Web
Hadoop to Snowflake New Web
capptixAI-case-study
lendingAI-logo_opt
CustomerAI_Logo_700x300 copy
sales-ai-logo-500x200