Magento Varnish CWP template

For one of my projects I had to configure a server with a hosting panel (preferrably a free one) and an online store. The only mandatory request was to use varnish as a caching mechanism.

I’ve decided to use CWP since it provides an easy way to configure varnish and I came up with this setup:

Nginx -> Varnish -> Apache

Nginx will listen on ports 80 and 443 and gets hits directly by the visitors, Varnish comes in as a middle layer and does what it’s best at: Caching. Apache will actually server the website.

Since CWP doesn’t have a default varnish template for Magento I had to create one (the default is kinda different than the varnish template suggested by Magento).

You can find the template here: Magento2 Varnish CWP Template.

How to use it?

Login as root on the CWP server, go to /usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/varnish and save the template from github there.

Then login using ssh, as root, on the CWP server.

Once the rebuild is done:


About Author

I am a linux passionate and currently working as a Linux Senior System Administrator. I also am a freelancer and help people to complete different jobs. You can hire me on


  1. The default varnish template from magento 2.4.x should be compatible with varnish 6.x as far as I know. You will still have to use vcl 4.0 at the beginning of the template even if your varnish version is 5.x or 6.x.

    The template from this post was creating on a CWP server while running varnish 5.x I believe but it will work for varnish 6.x as well with the exact same template

    • I see this snippet (below) in the varnish 6 vcl, generated from fom magento 2.4. that is the x-pool flag. Does this have to be added to your template (if yes how do i do it):

      # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
      # has been added to the response in your backend server config. This is used, for example, by the
      # capistrano-magento2 gem for purging old content from varnish during it’s deploy routine.
      if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
      return (synth(400, “X-Magento-Tags-Pattern or X-Pool header required”));
      if (req.http.X-Magento-Tags-Pattern) {
      ban(“obj.http.X-Magento-Tags ~ ” + req.http.X-Magento-Tags-Pattern);
      if (req.http.X-Pool) {
      ban(“obj.http.X-Pool ~ ” + req.http.X-Pool);

      • That I do not know exactly since I do not use any automatic deployment tools like capistrano. Are you actually doing automated magento deployments?

        I guess you could add it under the right section in VCL sub (not sure where exactly). Check the magento generated vcl file, see in which section you find that and then add that section in the varnish CWP template.

Leave A Reply

Get new posts by email: