Call us! (ID:64475)
+1-727-546-4678
HomeBlogHow to optimize Varnish Cache for WooCommerce #FasterHosting

How to optimize Varnish Cache for WooCommerce #FasterHosting

Varnish Cache is a reverse proxy used to accelerate HTTP speed and is used by many heavy-trafficked websites, like Wikipedia, Facebook and Twitter. Varnish can do miracles for your WooCommerce website, if properly optimized. You will have to configure it manually with Varnish VLC. It sounds complicated, but following our guide, you'll find is easy as pie.

Configure Varnish VCL for WooCommerce

You can of course adjust these parameters for your particular website and its hosting environment, but this configuration will work on most sites, and certainly on our servers. We will start by showing you how to launch Varnish in our hosting control panel, so if you're on another host, just skip to the code.

  1. Log in to the control panel. With ServerU.net you get logged in fast and easy with Facebook or Google+ login.
  2. Go to Varnish. In our control panel it is easy to find: Launch Varnish Cache
    Varnish is included in the Unlimited and Supreme hosting plans. For other hosting plans, you can add Varnish in the Upgrade Services section of the control panel.
    See how
    Add or upgrade hosting services
  3. Click the button Create Instance in the upper right corner. Create Varnish Instance
  4. In the box that opens, click Manual configuration. Configure Varnish VCL
  5.  
  6. Paste the following code into the text field and click Add. backend default { .host = "127.0.0.1"; .port = "8080"; } sub vcl_recv { if (req.request != "GET" && req.request != "HEAD" && req.request != "PUT" && req.request != "TRACE" && req.request != "OPTIONS" && req.request != "DELETE") { return (pipe); } # don't cache POSTs if (req.request == "POST") { return (pipe); } # don't cache for users logged into WP backend if (req.http.Cookie ~ "wordpress_logged_in_") { return (pipe); } if (req.url ~ "wp-(login|admin)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php" ) { return (pipe); } # don't cache ajax requests if (req.http.X-Requested-With == "XMLHttpRequest") { return (pipe); } if (req.url ~ "^/(cart|my-account|checkout|addons|sitemap)") { return (pipe); } if (req.url ~ "/feed/") { return (pipe); } unset req.http.cookie; return (lookup); } sub vcl_fetch { if (beresp.status == 404) { set beresp.ttl = 0m; return (hit_for_pass); } unset beresp.http.set-cookie; set beresp.ttl = 60m; return (deliver); } sub vcl_deliver { if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; } } sub vcl_pipe { set bereq.http.connection = "close"; }

Congratulations! You have now created a Varnish VCL configuration that optimized for your WooCommerce web shop. Please comment on how it works for you. Any suggestions for improvement will be appreciated.

Read more about Varnish VCL configuration at the Varnish website.

2 Comments

  1. Posted August 16, 2017 at 8:58 am | Permalink

    if i dont use cache plugin will it speed up for my woocommerce store

    • Posted August 16, 2017 at 9:55 am | Permalink

      Hello Ahasan, and welcome! Yes, Varnish will speed up your WooCommerce store even if you do not use a cache plugin. It is worthwhile!

Post a Reply to ahasan

You must be logged in to post a comment.