{"id":265,"date":"2022-12-05T07:48:28","date_gmt":"2022-12-05T07:48:28","guid":{"rendered":"http:\/\/thekraftors.com\/blog\/?p=265"},"modified":"2022-12-05T07:58:19","modified_gmt":"2022-12-05T07:58:19","slug":"how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/","title":{"rendered":"How To Speed Up Static Web Pages With Varnish Cache Server on Ubuntu 20.04"},"content":{"rendered":"\n<p class=\"has-black-color has-text-color\">Varnish&nbsp;is a versatile reverse HTTP proxy that caches responses from backend servers in memory so they are served quickly when requested again. It uses HTTP headers to determine whether to cache the responses to a particular request. By default, it does not cache responses with cookies because those are considered client-specific requests; however you can change this setting in the configuration file.<\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">Besides acting as a caching server, Varnish can be used as a:<\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">Web application firewall<\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">DDoS attack defender<\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">Load balancer<\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">Quick fix for unstable backends<\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">HTTP route<\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">There are three locations where the HTTP cache can be saved:<\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">In this tutorial, you will set up Varnish as a caching reverse proxy server. You\u2019ll then test the setup with Varnish against a non-caching configuration using wrk<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>To complete this, you will need:<\/p>\n\n\n\n<p>One Ubuntu 20.04 server with at least 2 GB of RAM<\/p>\n\n\n\n<p>A non-root user with sudo privileges as described in this Ubuntu 20.04 initial server setup guide<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1 \u2014 Installing Varnish And Apache<\/h2>\n\n\n\n<p>To start, you\u2019ll install Apache and Varnish. First update&nbsp;<code>apt-get<\/code>, and then install Apache with these commands:<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#e2e7eb\"><strong>$ sudo apt-get update<\/strong><\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#e2eaee\"><strong>$ sudo apt-get install apache2 \u2013y<\/strong><\/p>\n\n\n\n<p>You\u2019ll see output indicating that Apache is being installed.<\/p>\n\n\n\n<p>After the Apache installation process is complete, install Varnish with this command:<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#dfe5eb\"><strong>$ sudo apt-get install varnish \u2013y<\/strong><\/p>\n\n\n\n<p>You\u2019ll see output indicating that Varnish is being installed.<\/p>\n\n\n\n<p>Next, make sure both packages installed correctly. First, use this command to check the status of Apache:<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#dde2e7\"><strong>$ sudo systemctl status apache2<\/strong><\/p>\n\n\n\n<p>The output will look similar to this:<\/p>\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#e1e2e5\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p><strong>Output<\/strong><\/p>\n\n\n\n<p><strong>root@ubuntu-s-1vcpu-2gb-fra1-01:~# sudo systemctl status apache2<\/strong><\/p>\n\n\n\n<p><strong>\u25cf apache2.service &#8211; The Apache HTTP Server<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp; <strong>Loaded: loaded (\/lib\/systemd\/system\/apache2.service; enabled; vendor preset: enabled)<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp; <strong>Active: active (running) since Wed 2021-08-04 18:58:39 UTC; 4min 10s ago<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>Docs: https:\/\/httpd.apache.org\/docs\/2.4\/<\/strong><\/p>\n\n\n\n<p>&nbsp;    &nbsp; <strong>Main PID: 2279 (apache2)<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>Tasks: 55 (limit: 2344)<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;<strong> Memory: 5.0M<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp; <strong>CGroup: \/system.slice\/apache2.service<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>\u251c\u25002279 \/usr\/sbin\/apache2 -k start<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong> \u251c\u25002281 \/usr\/sbin\/apache2 -k start<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>\u2514\u25002282 \/usr\/sbin\/apache2 -k start<\/strong><\/p>\n\n\n\n<p><strong>Aug 04 18:58:39 ubuntu-s-1vcpu-2gb-fra1-01 systemd[1]: Starting The Apache HTTP Server&#8230;<\/strong><\/p>\n\n\n\n<p><strong>Aug 04 18:58:39 ubuntu-s-1vcpu-2gb-fra1-01 apachectl[2278]: AH00558: apache2: Could not reliably determine the server&#8217;s fully qualified domain name, using 127.0.1.1. Set the &#8216;ServerName&#8217; di&gt;<\/strong><\/p>\n\n\n\n<p><strong>Aug 04 18:58:39 ubuntu-s-1vcpu-2gb-fra1-01 systemd[1]: Started The Apache HTTP Server.<\/strong><\/p>\n<\/div><\/div>\n\n\n\n<p>Press the Q key to exit the status command.<\/p>\n\n\n\n<p>Next, check the status of Varnish with this command:<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#e3e6e8\"><strong>$ sudo systemctl status varnish<\/strong><\/p>\n\n\n\n<p>The output will look similar to this:<\/p>\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#e4e6e6\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<pre class=\"wp-block-preformatted\">Output<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>root@ubuntu-s-1vcpu-2gb-fra1-01:~# sudo systemctl status varnish<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u25cf varnish.service - Varnish HTTP accelerator<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&nbsp;&nbsp;&nbsp;&nbsp; Loaded: loaded (\/lib\/systemd\/system\/varnish.service; enabled; vendor preset: enabled)<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&nbsp;&nbsp;&nbsp;&nbsp; Active: active (running) since Wed 2021-08-04 18:59:09 UTC; 4min 41s ago<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>Docs: https:\/\/www.varnish-cache.org\/docs\/6.1\/<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong> man:varnishd<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&nbsp;&nbsp; Main PID: 3423 (varnishd)<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tasks: 217 (limit: 2344)<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&nbsp;&nbsp;&nbsp;&nbsp; Memory: 10.7M<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&nbsp;&nbsp;&nbsp;&nbsp; CGroup: \/system.slice\/varnish.service<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u251c\u25003423 \/usr\/sbin\/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f \/etc\/varnish\/default.vcl -S \/etc\/varnish\/secret -s malloc,256m<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u2514\u25003447 \/usr\/sbin\/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f \/etc\/varnish\/default.vcl -S \/etc\/varnish\/secret -s malloc,256m<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Aug 04 18:59:09 ubuntu-s-1vcpu-2gb-fra1-01 systemd&#91;1]: Started Varnish HTTP accelerator.<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Aug 04 18:59:10 ubuntu-s-1vcpu-2gb-fra1-01 varnishd&#91;3423]: Debug: Version: varnish-6.2.1 revision 9f8588e4ab785244e06c3446fe09bf9db5dd8753<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Aug 04 18:59:10 ubuntu-s-1vcpu-2gb-fra1-01 varnishd&#91;3423]: Version: varnish-6.2.1 revision 9f8588e4ab785244e06c3446fe09bf9db5dd8753<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Aug 04 18:59:10 ubuntu-s-1vcpu-2gb-fra1-01 varnishd&#91;3423]: Debug: Platform: Linux,5.4.0-73-generic,x86_64,-junix,-smalloc,-sdefault,-hcritbit<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Aug 04 18:59:10 ubuntu-s-1vcpu-2gb-fra1-01 varnishd&#91;3423]: Platform: Linux,5.4.0-73-generic,x86_64,-junix,-smalloc,-sdefault,-hcritbit<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Aug 04 18:59:10 ubuntu-s-1vcpu-2gb-fra1-01 varnishd&#91;3423]: Debug: Child (3447) Started<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Aug 04 18:59:10 ubuntu-s-1vcpu-2gb-fra1-01 varnishd&#91;3423]: Child (3447) Started<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Aug 04 18:59:10 ubuntu-s-1vcpu-2gb-fra1-01 varnishd&#91;3423]: Info: Child (3447) said Child starts<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Aug 04 18:59:10 ubuntu-s-1vcpu-2gb-fra1-01 varnishd&#91;3423]: Child (3447) said Child starts<\/strong><\/code><\/pre>\n<\/div><\/div>\n\n\n\n<p>If you do not see both services up and running, wait a few minutes until they are fully loaded, and keep both of them running.<\/p>\n\n\n\n<p>Now that you have Apache2 Varnish, installed, you\u2019ll give Varnish something to serve, in this case Apache\u2019s static web page.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2 \u2014 Configuring Varnish To Serve Apache\u2019s Static Web Page<\/h2>\n\n\n\n<p>In the previous step, you installed Varnish, and next you\u2019ll need to configure it. By default, Varnish listens on port 6081 and connects to a local web server on port 8080. You\u2019ll change that to serve the Apache static site from Apache server.<\/p>\n\n\n\n<p>First, you\u2019ll change Varnish\u2019s listening port to 8080. Usually you would want the listening port to be 80, but because you are running Apache and Varnish on the same server, you\u2019ll use port 8080 for Varnish and port 80 for Apache.<\/p>\n\n\n\n<p>There is no configuration option to change the listening port for Varnish, so you\u2019ll do it using the command line. You\u2019ll create a file called customexec.conf in a new directory called varnish.service.d in \/etc\/systemd\/system\/ that will change the default ports.<\/p>\n\n\n\n<p>Use the mkdir command to create the new directory:<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#e0e5e8\"><strong>$ sudo mkdir \/etc\/systemd\/system\/varnish.service.d<\/strong><\/p>\n\n\n\n<p>Use your favorite text editor to create a new file called&nbsp;<code>customexec.conf<\/code>&nbsp;:<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#e7eaed\"><strong>$ sudo nano \/etc\/systemd\/system\/varnish.service.d\/customexec.conf<\/strong><\/p>\n\n\n\n<p>In&nbsp;<code>customexec.conf<\/code>, add the following content:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/etc\/systemd\/system\/varnish.service.d\/customexec.conf file<\/pre>\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#dde0e4\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<pre class=\"wp-block-code\"><code><strong>&#91;Service]<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>ExecStart=<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>ExecStart=\/usr\/sbin\/varnishd -j unix,user=vcache -F -a :8080 -T localhost:6082 -f \/etc\/varnish\/default.vcl -S \/etc\/varnish\/secret -s malloc,256m<\/strong><\/code><\/pre>\n<\/div><\/div>\n\n\n\n<p>In this file you are changing the Service section of the Varnish configuration. First you remove the old value for the ExecStart option, and then you assign a new value for it.<\/p>\n\n\n\n<p>The new value specifies the binary file used to run Varnish with the following options:<\/p>\n\n\n\n<p>-j: Specifies the jailing mechanism to use. Varnish jails are used to reduce the permissions for the varnish process over various platform-specific methods. Here you\u2019re using the unix mechanism and the user vcache to limit the permissions. This is default for varnish on Ubuntu systems.<\/p>\n\n\n\n<p>-F: Indicates that the server should run in the foreground, because systemd expects the main process to keep running so it can track it, and not fork a new process and die.<\/p>\n\n\n\n<p>-a: This flag is used to specify the IP address and port for accepting client connections. The IP in this case is empty, which means the server will accept all IPs. The port is set to 8080.<\/p>\n\n\n\n<p>-T: This flag specifies the IP address and port for management interface, in this case localhost and port 6082.<\/p>\n\n\n\n<p>-f: This flag specifies the default VCL file for Varnish configuration. You will edit this file later in this tutorial to configure Varnish to connect to the Apache server.<\/p>\n\n\n\n<p>-S: This flag specifies a shared secret file for authorizing access to the management interface. The \/etc\/varnish\/secret value is the default for Varnish on Ubuntu. You will not use the secret file in this tutorial.<\/p>\n\n\n\n<p>-s: This flag indicates where and how to store objects. The value malloc,256m is the default one for Vanish. It means to store various Varnish objects in memory using the malloc system call and a maximum size of 256 megabytes. Other possible values are default, which uses umem when malloc is not available, or file, which stores objects in a file on the disk.<\/p>\n\n\n\n<p>Save and close the customexec.conf file. Then execute this command to reload the systemd services file from disk:<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#e1e3e5\"><strong>$ sudo systemctl daemon-reload<\/strong><\/p>\n\n\n\n<p>Then restart Varnish for changes to take effect.<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#dde0e4\"><strong>$ sudo systemctl restart varnish<\/strong><\/p>\n\n\n\n<p>You won\u2019t see any output from these last two commands. To make sure that Varnish is now listening on port 8080, use the&nbsp;<code>netstat<\/code>&nbsp;command to display all listening TCP sockets on the server.<\/p>\n\n\n\n<p><strong>$ sudo netstat -ltnp | grep 8080<\/strong><\/p>\n\n\n\n<p>You\u2019ll see output that looks like this:<\/p>\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#dadde1\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<pre class=\"wp-block-preformatted\"><strong>Output<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>tcp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 0.0.0.0:8080&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.0.0.0:*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LISTEN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 18689\/varnishd<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>tcp6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 :::8080&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :::*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LISTEN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 18689\/varnishd<\/strong><\/code><\/pre>\n<\/div><\/div>\n\n\n\n<p>Now that Varnish is running and listening to port 8080, you need to edit the default configuration file located at \/etc\/varnish\/default.vcl:<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#dadfe3\"><strong>$ sudo nano \/etc\/varnish\/default.vcl<\/strong><\/p>\n\n\n\n<p>Navigate to the backend default block, and then change .port to 80, as shown here:<\/p>\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#d5dadf\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<pre class=\"wp-block-preformatted\"><strong>default.vcl file<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong># Default backend definition. Set this to point to your content server.<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>backend default {<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&nbsp;&nbsp;&nbsp; .host = \"127.0.0.1\";<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>&nbsp;&nbsp;&nbsp; .port = \"80\";<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>}<\/strong><\/code><\/pre>\n<\/div><\/div>\n\n\n\n<p>Save and close the default.vcl file, then restart Varnish with this command:<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#d9dfe4\"><strong>$ sudo systemctl restart varnish<\/strong><\/p>\n\n\n\n<p>If everything is fine, there won\u2019t be any output. Open&nbsp; in your browser, and you\u2019ll see the Apache static site, opened using Varnish.<\/p>\n\n\n\n<p>You now have Apache and Varnish running together on the same Droplet, with Apache listening to port 80 and Varnish to port 8080. Next, you\u2019ll compare the response times of both servers using the wrk tool.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Configure Magento to use Varnish<\/h2>\n\n\n\n<p>To configure Magento for using Varnish, you need to enable&nbsp;Full Page Cache. Please go to&nbsp;Stores &gt; Configuration &gt; Advanced &gt; System &gt; Full Page Cache, you will see the below image:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"463\" src=\"http:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-1024x463.png\" alt=\"\" class=\"wp-image-267\" srcset=\"https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-1024x463.png 1024w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-300x136.png 300w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-768x347.png 768w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image.png 1069w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Enable Full Page Cache<\/p>\n\n\n\n<p>Then, choose&nbsp;Varnish Cache&nbsp;from the&nbsp;Caching Application&nbsp;list.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"448\" src=\"http:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-1-1024x448.png\" alt=\"\" class=\"wp-image-268\" srcset=\"https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-1-1024x448.png 1024w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-1-300x131.png 300w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-1-768x336.png 768w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-1.png 1083w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Caching Application<\/p>\n\n\n\n<p>Next step, you can change the value in&nbsp;<strong>TTL for public content<\/strong>&nbsp;field by increasing or decreasing the lifetime value of the public content cache if you want.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"190\" src=\"http:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-2-1024x190.png\" alt=\"\" class=\"wp-image-269\" srcset=\"https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-2-1024x190.png 1024w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-2-300x56.png 300w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-2-768x143.png 768w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-2.png 1044w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>for public content<\/p>\n\n\n\n<p>Afterward, by expanding the&nbsp;<strong>Varnish Configuration<\/strong>&nbsp;and entering the following details, you can enable advanced options.<\/p>\n\n\n\n<p>Determine the IP or Host that is allowed to delete the Varnish Cache in the \u201cAccess list\u201d. Then, please add your domain name of the application in this field.<\/p>\n\n\n\n<p>Determine the Backend Host.<\/p>\n\n\n\n<p>Backend Port is the port of the Apache server.<\/p>\n\n\n\n<p>Define the Grace period to know the time Varnish servers stale content suppose the backend is not responding.<\/p>\n\n\n\n<p>Finally, please click on the&nbsp;<strong>Save Config<\/strong>&nbsp;button if you are done. Another way to enable Magento 2 Varnish, you can do it through the command line interface via SSH. If doing this way, please use the following commands:<\/p>\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#d7dadd\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<pre class=\"wp-block-code\"><code><strong>bin\/magento <\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>config:set--scope=default--scope-code=0system\/full_page_cache\/caching_application 2<\/strong><\/code><\/pre>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">How to Verify Varnish in Magento 2<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Check suppose Varnish is listening to port 80<\/strong><\/h3>\n\n\n\n<p>To check if Varnish is listening to port 80, please run the command below:<\/p>\n\n\n\n<p><code>netstat -tulpn | grep varnished<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"129\" src=\"http:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-3-1024x129.png\" alt=\"\" class=\"wp-image-270\" srcset=\"https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-3-1024x129.png 1024w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-3-300x38.png 300w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-3-768x97.png 768w, https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-3.png 1050w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Verify Varnish in Magento 2<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Verify your contents in var\/cache, var\/page_cache folder is not recreated<\/h3>\n\n\n\n<p>Once FPC is cleared, cache folders (var\/cache, var\/page_cache) should be empty because FPC is set up to serve the content from Varnish.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final words<\/h2>\n\n\n\n<p>To sum up,&nbsp;<strong>integrating Varnish Cache in Magento 2<\/strong>&nbsp;is an ideal solution for your online store if you want to instantly reduce the page load time and&nbsp;increase the page load speed. Thanks to this integration, your website will not only enhance the user experience, but it also helps boost sales dramatically. Only with some minimal changes can you beautify your online business quickly.<\/p>\n\n\n\n<p>If I have missed any key points related to this topic, or you have any contribution to any documentation for our blog, please feel free to comment below.<\/p>\n\n\n\n<p>Thank you for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Varnish&nbsp;is a versatile reverse HTTP proxy that caches responses from backend servers in memory so they are served quickly when requested again. It uses HTTP headers to determine whether to&hellip;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-265","post","type-post","status-publish","format-standard","hentry","category-devops"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Speed Up Static Web Pages With Varnish Cache Server on Ubuntu 20.04 - The Kraftors<\/title>\n<meta name=\"description\" content=\"Check out the latest news and trending articles on the latest technologies, such as AI, AR\/VR, and e-commerce. Mobile application and more.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Speed Up Static Web Pages With Varnish Cache Server on Ubuntu 20.04 - The Kraftors\" \/>\n<meta property=\"og:description\" content=\"Check out the latest news and trending articles on the latest technologies, such as AI, AR\/VR, and e-commerce. Mobile application and more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/\" \/>\n<meta property=\"og:site_name\" content=\"The Kraftors\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/thekraftors\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-05T07:48:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-12-05T07:58:19+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-1024x463.png\" \/>\n<meta name=\"author\" content=\"Ajeet Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@the_kraftors\" \/>\n<meta name=\"twitter:site\" content=\"@the_kraftors\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ajeet Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/\",\"url\":\"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/\",\"name\":\"How To Speed Up Static Web Pages With Varnish Cache Server on Ubuntu 20.04 - The Kraftors\",\"isPartOf\":{\"@id\":\"https:\/\/thekraftors.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-1024x463.png\",\"datePublished\":\"2022-12-05T07:48:28+00:00\",\"dateModified\":\"2022-12-05T07:58:19+00:00\",\"author\":{\"@id\":\"https:\/\/thekraftors.com\/blog\/#\/schema\/person\/45d29e37a8abbe89d690103dbed36899\"},\"description\":\"Check out the latest news and trending articles on the latest technologies, such as AI, AR\/VR, and e-commerce. Mobile application and more.\",\"breadcrumb\":{\"@id\":\"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/#primaryimage\",\"url\":\"https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image.png\",\"contentUrl\":\"https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image.png\",\"width\":1069,\"height\":483},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/thekraftors.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Speed Up Static Web Pages With Varnish Cache Server on Ubuntu 20.04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/thekraftors.com\/blog\/#website\",\"url\":\"https:\/\/thekraftors.com\/blog\/\",\"name\":\"The Kraftors\",\"description\":\"AI | AR | eCommerce | Devops | Magento | Flutter\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/thekraftors.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/thekraftors.com\/blog\/#\/schema\/person\/45d29e37a8abbe89d690103dbed36899\",\"name\":\"Ajeet Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/thekraftors.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f2d799a03ab24318174556b39ac9de67784b8a874a308e3a5fd374fe2199a51d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f2d799a03ab24318174556b39ac9de67784b8a874a308e3a5fd374fe2199a51d?s=96&d=mm&r=g\",\"caption\":\"Ajeet Kumar\"},\"url\":\"https:\/\/thekraftors.com\/blog\/author\/ajeet\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Speed Up Static Web Pages With Varnish Cache Server on Ubuntu 20.04 - The Kraftors","description":"Check out the latest news and trending articles on the latest technologies, such as AI, AR\/VR, and e-commerce. Mobile application and more.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/","og_locale":"en_US","og_type":"article","og_title":"How To Speed Up Static Web Pages With Varnish Cache Server on Ubuntu 20.04 - The Kraftors","og_description":"Check out the latest news and trending articles on the latest technologies, such as AI, AR\/VR, and e-commerce. Mobile application and more.","og_url":"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/","og_site_name":"The Kraftors","article_publisher":"https:\/\/www.facebook.com\/thekraftors\/","article_published_time":"2022-12-05T07:48:28+00:00","article_modified_time":"2022-12-05T07:58:19+00:00","og_image":[{"url":"http:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-1024x463.png"}],"author":"Ajeet Kumar","twitter_card":"summary_large_image","twitter_creator":"@the_kraftors","twitter_site":"@the_kraftors","twitter_misc":{"Written by":"Ajeet Kumar","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/","url":"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/","name":"How To Speed Up Static Web Pages With Varnish Cache Server on Ubuntu 20.04 - The Kraftors","isPartOf":{"@id":"https:\/\/thekraftors.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/#primaryimage"},"image":{"@id":"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/#primaryimage"},"thumbnailUrl":"http:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image-1024x463.png","datePublished":"2022-12-05T07:48:28+00:00","dateModified":"2022-12-05T07:58:19+00:00","author":{"@id":"https:\/\/thekraftors.com\/blog\/#\/schema\/person\/45d29e37a8abbe89d690103dbed36899"},"description":"Check out the latest news and trending articles on the latest technologies, such as AI, AR\/VR, and e-commerce. Mobile application and more.","breadcrumb":{"@id":"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/#primaryimage","url":"https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image.png","contentUrl":"https:\/\/thekraftors.com\/blog\/wp-content\/uploads\/2022\/12\/image.png","width":1069,"height":483},{"@type":"BreadcrumbList","@id":"https:\/\/thekraftors.com\/blog\/how-to-speed-up-static-web-pages-with-varnish-cache-server-on-ubuntu-20-04\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thekraftors.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Speed Up Static Web Pages With Varnish Cache Server on Ubuntu 20.04"}]},{"@type":"WebSite","@id":"https:\/\/thekraftors.com\/blog\/#website","url":"https:\/\/thekraftors.com\/blog\/","name":"The Kraftors","description":"AI | AR | eCommerce | Devops | Magento | Flutter","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thekraftors.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/thekraftors.com\/blog\/#\/schema\/person\/45d29e37a8abbe89d690103dbed36899","name":"Ajeet Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/thekraftors.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f2d799a03ab24318174556b39ac9de67784b8a874a308e3a5fd374fe2199a51d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f2d799a03ab24318174556b39ac9de67784b8a874a308e3a5fd374fe2199a51d?s=96&d=mm&r=g","caption":"Ajeet Kumar"},"url":"https:\/\/thekraftors.com\/blog\/author\/ajeet\/"}]}},"_links":{"self":[{"href":"https:\/\/thekraftors.com\/blog\/wp-json\/wp\/v2\/posts\/265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thekraftors.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thekraftors.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thekraftors.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/thekraftors.com\/blog\/wp-json\/wp\/v2\/comments?post=265"}],"version-history":[{"count":4,"href":"https:\/\/thekraftors.com\/blog\/wp-json\/wp\/v2\/posts\/265\/revisions"}],"predecessor-version":[{"id":274,"href":"https:\/\/thekraftors.com\/blog\/wp-json\/wp\/v2\/posts\/265\/revisions\/274"}],"wp:attachment":[{"href":"https:\/\/thekraftors.com\/blog\/wp-json\/wp\/v2\/media?parent=265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thekraftors.com\/blog\/wp-json\/wp\/v2\/categories?post=265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thekraftors.com\/blog\/wp-json\/wp\/v2\/tags?post=265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}