The Varnish cache is an HTTP accelerator (sometimes it’s called a reverse HTTP proxy) enabling which you are able to handle much more traffic without website’s speed or performance come-down due to the reduction of the loading time. The cache option is also useful when working in the production mode, as the variant is much faster and allows for caching of most of the website content. The solution is good for websites of various size as it’s developed for web performance betterment. However, the technology is pretty confusing and requires some technical knowledge.
Note: Learn how to install varnish on Magento 2 in the official documentation.
After the Full Page Cache is configured and Varnish Caching is chosen in the Caching Application field:
you need to make the additional configuration in the section:
Enter IPs access lists that can purge Varnish configuration. If you leave the field unchanged a default localhost will remain there.
Add the backend host. If you leave the field unchanged a default localhost will remain there.
Indicate the backend port here.
Choose the Varnish version you use.
Once it’s done, click the Save Config button.
The action is optional and required in case of the backend host or/and port number change that has been defined during the Magento 2 Varnish setup.
E.g.: acl purge {
"localhost";
}
service varnish restart
service httpd restart
In the Magento developer mode run curl (other utility) to see response headers:
E.g.: curl -I -v --location-trusted 'http://192.0.2.55/magento2'
Valuable headers: X-Magento-Cache-Control: max-age=86400, public, s-maxage=86400
Age: 0
X-Magento-Cache-Debug: MISS
Redis: can operate together; both the Redis and Varnish cache remains invalidated after the content is updated. So, there is hardly any sense in it.
Nginx (SSL): as long as SSL/TSL doesn’t support Varnish, with the help of Nginx you can solve the issue, which means you can enable Magento 2 Varnish cache while using the SSL.
See also: Learn how to configure the Flush Magento 2 Cache button to purge Varnish in Magento 2 documentation.
Having made everything correctly, you are still dissatisfied with the result, run the Magento 2 Full Page Cache Warmer extension. It will help you with smooth cache management.
For faster pages loading, try our Google Page Speed Optimizer.
Login and Registration Form