Editing Varnish

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 723: Line 723:
 
==How to Configure Varnish for MediaWiki==
 
==How to Configure Varnish for MediaWiki==
  
If you want to use Varnish with MediaWiki, this VCL should work for Varnish 4.0 and above. I have found that using '''[[Apache|Apache Event]]''' and '''[[GooglePageSpeed|mod_pagespeed]]''' provided better page load times and lower application response times compared to using Varnish.
+
Visit this link for a Varnish 4 VCL Example [http://wiki.mikejung.biz/index.php?title=How_to_Configure_Varnish_for_MediaWiki MediaWiki Example VCL]
<pre>
 
vim /etc/varnish/default.vcl
 
</pre>
 
 
 
This is an example VCL file
 
<pre>
 
# Default backend definition. Set this to point to your content server.
 
backend default {
 
    .host = "$back_end_IP";
 
    .port = "8080";
 
}
 
 
 
 
 
 
 
sub vcl_recv {
 
 
 
set req.http.X-Forwarded-For = client.ip;
 
 
 
set req.backend_hint= default;
 
 
 
if (req.method != "GET" && req.method != "HEAD" &&
 
            req.method != "PUT" && req.method != "POST" &&
 
            req.method != "TRACE" && req.method != "OPTIONS" &&
 
            req.method != "DELETE")
 
            {return(pipe);}
 
 
 
if (req.method != "GET" && req.method != "HEAD")
 
          {return(pass);}
 
 
 
if (req.http.Authorization || req.http.Cookie)
 
          {return(pass);}
 
 
 
if (req.http.If-None-Match)
 
          {return(pass);}
 
 
 
if (req.http.Accept-Encoding) {
 
          if (req.http.User-Agent ~ "MSIE 6") {
 
            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;
 
          }
 
        }
 
 
        return(hash);
 
 
 
}
 
 
 
 
 
 
 
sub vcl_backend_response {
 
set beresp.grace = 120s;
 
if (beresp.ttl < 48h) {
 
          set beresp.uncacheable = true;
 
          return (deliver);
 
        }
 
 
        if (!beresp.ttl > 0s) {
 
          set beresp.uncacheable = true;
 
          return (deliver);
 
        }
 
 
        if (beresp.http.Set-Cookie) {
 
          set beresp.uncacheable = true;
 
          return (deliver);
 
 
 
}
 
}
 
 
 
sub vcl_deliver {
 
    # Happens when we have all the pieces we need, and are about to send the
 
    # response to the client.
 
    #
 
    # You can do accounting or modifying the final object here.
 
}
 
</pre>
 
  
 
==Varnish and mod_pagespeed==
 
==Varnish and mod_pagespeed==

Please note that all contributions to wiki.mikejung.biz may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see wiki.mikejung.biz:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)