Putting Varnish in Front of Magento 2
Varnish serves cached pages straight from memory, which makes a big difference to Magento 2 response times under load.
1. Install Varnish
sudo apt update sudo apt install varnish
Check the version:
varnishd -V
2. Switch Magento to Varnish
In the admin go to Stores > Configuration > Advanced > System > Full Page Cache, choose Varnish and save. Export the VCL for your Varnish version from the same screen.
3. Install the VCL
sudo mv /etc/varnish/default.vcl /etc/varnish/default.vcl.backup sudo nano /etc/varnish/default.vcl
Paste the exported file into default.vcl, then restart:
sudo systemctl restart nginx varnish php bin/magento cache:flush
4. Confirm it works
Delete var/page_cache, browse the site, and check the folder stays empty. That means pages are coming from Varnish.
Want this done for you? Find out more about our Magento development service.