Magento2 Varnish CWP template - One of my projects from freelancer.com involved the configuration of a linux server, with a hosting panel (preferrably an open source or free one) for an online store built using Magento2. Mandatory requirement: Varnish as a caching mechanism since the website speed was an important factor.
I’ve decided to use CentOS WebPanel or shortly CWP since it provides, by default, support for configurations involving Apache, Nginx, and/or Varnish.
The setup I came up with in the end was this: Nginx -> Varnish -> Apache
Nginx will listen on ports 80 (HTTP), 443 (HTTPS) and it’s hitted directly by the website visitors. Varnish comes in as a middle layer and does what it’s best at: Caching. Apache will actually take care of the website and PHP.
CWP doesn’t provide a default varnish template for Magento so I had to create one.
You can check the template on my personal GitHub repository: Magento2 Varnish CWP Template.
How to use it?
Login as root on the CWP server via SSH, then:
Login to CWP, as admin, in a web browser and use the menu on the left by selection the options bellow:
Select WebServers -> Select the last option -> Save & Rebuild
WebServer Settings -> WebServers DomainConf -> Select a username -> Create a new Config