Â
Varnish Cache is an open-source web application accelerator (also known as HTTP accelerator or HTTP reverse proxy caching). To speed up subsequent requests, Varnish temporarily stores website elements (files or fragments) in memory. This focus on in-memory caching for the HTTP protocol allows Varnish to significantly reduce response times and network traffic. This allows Varnish in Magento 2 to significantly reduce response time and network bandwidth consumption on future equivalent requests.
Magento 2.4.2 has been specifically tested for compatibility with Varnish 6.4. While all versions of Magento 2.4 are compatible with Varnish 6.x, Magento strongly recommends using Varnish in a production environment. Varnish, designed to accelerate HTTP traffic, significantly outperforms Magento’s built-in full-page caching stored in the file system or database.
You can find more information in the link below:
Varnish Topology Diagram
The following figure shows you a basic view of Varnish in Magento topology.
In the figure above, you can see how HTTP requests from users on the Internet result in numerous requests for CSS, HTML, JavaScript, and images (collectively referred to as resources). Varnish stands in front of the web server and forwards these requests to the web server.
Upon receiving a request, the web server identifies cacheable resources. These resources are then stored in Varnish, which fulfils subsequent requests for them directly. This bypasses the web server, improving performance. Varnish then returns the cached content extremely quickly. The benefits include faster response times for content delivery and a lower request load on Magento.
Resources cached by Varnish expire at a configurable interval or are replaced by newer versions of the same resources. You can also clear the cache manually using Magento Admin or the magento cache: clean command .
In this section, we will see how to initially install Varnish with a minimum set of parameters and test its operation. Then you will export a Varnish configuration from the Magento admin and test it again.
The process can be summarized as follows:
If there is nothing in your <magento_root> / var / page_cache directory, you have successfully configured Varnish with Magento!
Unless otherwise specified, you must enter all the commands discussed above, as a user with root privileges.
This applies to Varnish on CentOS and Apache 2.4. If you are setting up Varnish in a different environment, some commands may be different. Consult the Varnish documentation for more information.
In this process some problems can arise, let’s see which ones:
Error 503 Service Unavailable
Service Unavailable
XID: 303394517
Varnish cache server
|
If this error occurs, edit default.vcl and add a timeout to the backend as follows:
backend default { .host = "127.0.0.1"; .port = "8080"; .first_byte_timeout = 600s; } |
Â
That’s it, folks! Check out our blog for more information.