I would like to kindly ask someone for help. I browsed a lot of pages containing Varnish tutorials and sample VCL files, but I can't find anything related to configurating Varnish for Magento (at least they don't function right).

All manuals I've found thrown a lot of errors during Varnish starting and it seems thay are suitable for old versions. (Also none of magento modules PageCache & Varnish Extension don't work for me, because I think Varnish itself is not working right)

My problem:
1. I get Varnish to cache front-end, but it breaks almost every functionalities of my forms, payment module, newsletter subscription, etc., etc.
2. I've found out that changing one word in "sub vcl_recv" changes everything The word is: return(lookup). This is the code of my "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)") {
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);

Can someone kindly help me with setting this up?

Any help would be greatly appreciated!!!

Thank you. Thomas

  • ////UPDATE//// Forgot to explain: 1. removing "return(lookup)" causes Varnish not-to-cache. Neither miss or hit apperas in "varnishstat", hitratio:0. | 2. leaving "return(lookup)" in vcl_recv causes Varnish to cache like it should, but it breaks lots of functionalities > on-line magento forms(like Contact us) don't send anything, payment module (paypal) throws error, newsletter subscription from home page doesn't function (it refreshes the page after sending e-mail, but nothing appears in admin area in Subscribers.) – Thomas Mar 7 '12 at 0:30

Looks that your Varnish is misconfigured

Basically you should pass requests to backend, if they are not GET or HEAD

if (req.request != "GET" && req.request != "HEAD") {
return (pass);

Next, you should review your session management and pass user to backend if some cookie present. Can't say anything about standard Magento cookies, not worked with it yet

|improve this answer|||||
  • WOW, MAN!!! It seems, you've solved this enormous problem for me!!!(strugling with this for 4 days now). I'm really looking for someone who can help me set-up and tune varnish vcl for Magento. I've browsed a lot of pages but everything related to this theme is outdated and throw many errors. I would like to kindly ask you, if anything comes up to your mind about this theme (Varnish + Magento), could you please share it with me? Maybe I can pay for your support. :) – Thomas Mar 7 '12 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.