{"id":16068,"date":"2026-09-19T17:51:21","date_gmt":"2026-09-19T16:51:21","guid":{"rendered":"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/"},"modified":"2026-09-19T17:51:21","modified_gmt":"2026-09-19T16:51:21","slug":"how-to-set-up-varnish-cache-on-your-vps","status":"publish","type":"post","link":"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/","title":{"rendered":"How to Set Up Varnish Cache on Your VPS"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_87 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#How_to_Set_Up_Varnish_Cache_on_Your_VPS\" >How to Set Up Varnish Cache on Your VPS<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#What_Is_Varnish_Cache_and_Why_Does_It_Matter\" >What Is Varnish Cache and Why Does It Matter?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Prerequisites_Before_You_Begin\" >Prerequisites Before You Begin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Step_1_Installing_Varnish_Cache_on_Your_VPS\" >Step 1: Installing Varnish Cache on Your VPS<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Adding_the_Varnish_Repository\" >Adding the Varnish Repository<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Step_2_Configuring_Your_Web_Server_to_Work_With_Varnish\" >Step 2: Configuring Your Web Server to Work With Varnish<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Changing_the_Apache_Listening_Port\" >Changing the Apache Listening Port<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Changing_the_Nginx_Listening_Port\" >Changing the Nginx Listening Port<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Step_3_Configuring_Varnish_to_Listen_on_Port_80\" >Step 3: Configuring Varnish to Listen on Port 80<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Editing_the_Varnish_Service_File\" >Editing the Varnish Service File<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Step_4_Editing_the_Varnish_VCL_Configuration_File\" >Step 4: Editing the Varnish VCL Configuration File<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Setting_the_Backend\" >Setting the Backend<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Step_5_Testing_Your_Varnish_Cache_VPS_Setup\" >Step 5: Testing Your Varnish Cache VPS Setup<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Step_6_Fine-Tuning_Your_Varnish_Configuration\" >Step 6: Fine-Tuning Your Varnish Configuration<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Increasing_Cache_Memory\" >Increasing Cache Memory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Excluding_Certain_Pages_From_Caching\" >Excluding Certain Pages From Caching<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-varnish-cache-on-your-vps\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<p><html><br \/>\n<head><br \/>\n<title>How to Set Up Varnish Cache on Your VPS<\/title><br \/>\n<\/head><br \/>\n<body><\/p>\n<h1><span class=\"ez-toc-section\" id=\"How_to_Set_Up_Varnish_Cache_on_Your_VPS\"><\/span>How to Set Up Varnish Cache on Your VPS<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>If you are running a website on a virtual private server and struggling with slow load times or high server load, implementing a Varnish cache VPS setup could be the solution you have been looking for. Varnish Cache is a powerful, open-source HTTP accelerator designed to dramatically speed up your web server by storing copies of pages in memory and serving them to visitors without repeatedly hitting your backend. In this guide, we will walk you through everything you need to know to get Varnish Cache up and running on your VPS.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_Is_Varnish_Cache_and_Why_Does_It_Matter\"><\/span>What Is Varnish Cache and Why Does It Matter?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Varnish Cache is a web application accelerator, also known as a caching HTTP reverse proxy. When a visitor requests a page from your website, Varnish intercepts that request and checks whether it already has a cached version available. If it does, it serves that cached version almost instantly, bypassing your web server entirely. If it does not, it fetches the content from your backend, stores it, and then delivers it to the user.<\/p>\n<p>The performance benefits of a Varnish cache VPS configuration are significant. Websites can see response times drop from hundreds of milliseconds to just a few milliseconds. This is particularly valuable for content-heavy websites, news portals, e-commerce platforms, and any site that experiences high traffic volumes. Faster load times also contribute positively to your search engine rankings, making Varnish an important tool not just for performance but for SEO as well.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Prerequisites_Before_You_Begin\"><\/span>Prerequisites Before You Begin<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before diving into the installation process, make sure you have the following in place:<\/p>\n<ul>\n<li>A VPS running Ubuntu 20.04 or 22.04 (this guide uses Ubuntu, though the steps are similar for Debian-based systems)<\/li>\n<li>Root or sudo access to your server<\/li>\n<li>A web server such as Apache or Nginx already installed and running<\/li>\n<li>Basic familiarity with the Linux command line<\/li>\n<\/ul>\n<p>For more general guidance on managing your VPS effectively, you can visit <a href=\"https:\/\/da-manager.com\/blog\" target=\"_blank\">da-manager.com\/blog<\/a> for a range of helpful tutorials and server management tips.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_1_Installing_Varnish_Cache_on_Your_VPS\"><\/span>Step 1: Installing Varnish Cache on Your VPS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The first step in your Varnish cache VPS setup is to install the software itself. Ubuntu&#8217;s default repositories include Varnish, but it is generally recommended to install from the official Varnish repository to get the latest stable version.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Adding_the_Varnish_Repository\"><\/span>Adding the Varnish Repository<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Open your terminal and run the following commands to add the official Varnish repository:<\/p>\n<pre>\ncurl -s https:\/\/packagecloud.io\/varnishcache\/varnish74\/gpgkey | sudo apt-key add -\nsudo apt-get install -y apt-transport-https\necho \"deb https:\/\/packagecloud.io\/varnishcache\/varnish74\/ubuntu\/ focal main\" | sudo tee \/etc\/apt\/sources.list.d\/varnishcache_varnish74.list\nsudo apt-get update\nsudo apt-get install varnish\n<\/pre>\n<p>Once the installation is complete, you can verify it by running <strong>varnishd -V<\/strong> to confirm the version installed.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_2_Configuring_Your_Web_Server_to_Work_With_Varnish\"><\/span>Step 2: Configuring Your Web Server to Work With Varnish<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>By default, your web server (Apache or Nginx) listens on port 80. Since Varnish will now act as the front-facing layer, you need to move your web server to a different port, typically port 8080, and let Varnish listen on port 80 instead.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Changing_the_Apache_Listening_Port\"><\/span>Changing the Apache Listening Port<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If you are using Apache, open the ports configuration file:<\/p>\n<pre>sudo nano \/etc\/apache2\/ports.conf<\/pre>\n<p>Change <strong>Listen 80<\/strong> to <strong>Listen 8080<\/strong>. Then update your virtual host file to reflect the same change, replacing port 80 with 8080. Restart Apache once done:<\/p>\n<pre>sudo systemctl restart apache2<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Changing_the_Nginx_Listening_Port\"><\/span>Changing the Nginx Listening Port<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If you are using Nginx, open your server block configuration file and change the <strong>listen 80<\/strong> directive to <strong>listen 8080<\/strong>. Save the file and restart Nginx:<\/p>\n<pre>sudo systemctl restart nginx<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_3_Configuring_Varnish_to_Listen_on_Port_80\"><\/span>Step 3: Configuring Varnish to Listen on Port 80<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now you need to configure your Varnish cache VPS setup so that Varnish listens on port 80 and forwards requests to your web server on port 8080.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Editing_the_Varnish_Service_File\"><\/span>Editing the Varnish Service File<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>On Ubuntu systems using systemd, you will need to edit the Varnish service file rather than the default configuration file:<\/p>\n<pre>sudo systemctl edit --full varnish<\/pre>\n<p>Find the line that begins with <strong>ExecStart<\/strong> and modify the <strong>-a<\/strong> flag to specify port 80:<\/p>\n<pre>ExecStart=\/usr\/sbin\/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f \/etc\/varnish\/default.vcl -S \/etc\/varnish\/secret -s malloc,256m<\/pre>\n<p>Save and close the file, then reload the systemd daemon and restart Varnish:<\/p>\n<pre>\nsudo systemctl daemon-reload\nsudo systemctl restart varnish\n<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_4_Editing_the_Varnish_VCL_Configuration_File\"><\/span>Step 4: Editing the Varnish VCL Configuration File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Varnish uses a domain-specific language called VCL (Varnish Configuration Language) to define how requests and responses should be handled. The main configuration file is located at <strong>\/etc\/varnish\/default.vcl<\/strong>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Setting_the_Backend\"><\/span>Setting the Backend<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Open the VCL file and ensure the backend definition points to your web server on port 8080:<\/p>\n<pre>\nbackend default {\n    .host = \"127.0.0.1\";\n    .port = \"8080\";\n}\n<\/pre>\n<p>This tells Varnish to forward all uncached requests to your local web server. Save the file and restart Varnish to apply the changes.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_5_Testing_Your_Varnish_Cache_VPS_Setup\"><\/span>Step 5: Testing Your Varnish Cache VPS Setup<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Once everything is configured, it is essential to verify that Varnish is working correctly. You can use the <strong>curl<\/strong> command to inspect response headers:<\/p>\n<pre>curl -I http:\/\/yourdomain.com<\/pre>\n<p>Look for a header that reads <strong>X-Varnish<\/strong> or <strong>Via: 1.1 varnish<\/strong> in the response. If you see these headers, Varnish is successfully intercepting and serving requests. You should also see an <strong>Age<\/strong> header on subsequent requests, indicating that content is being served from cache.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_6_Fine-Tuning_Your_Varnish_Configuration\"><\/span>Step 6: Fine-Tuning Your Varnish Configuration<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A basic Varnish installation will already provide noticeable performance improvements, but there are several additional tweaks worth considering for a more robust Varnish cache VPS environment.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Increasing_Cache_Memory\"><\/span>Increasing Cache Memory<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>By default, Varnish allocates 256MB of memory for caching. For high-traffic websites, you may want to increase this. In the ExecStart line of your service file, adjust the <strong>-s malloc<\/strong> value accordingly, for example to <strong>512m<\/strong> or <strong>1g<\/strong> depending on your VPS resources.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Excluding_Certain_Pages_From_Caching\"><\/span>Excluding Certain Pages From Caching<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Not all content should be cached. Login pages, checkout pages, and admin areas should typically be excluded. You can add logic to your VCL file to handle this:<\/p>\n<pre>\nsub vcl_recv {\n    if (req.url ~ \"^\/wp-admin\" || req.url ~ \"^\/checkout\") {\n        return (pass);\n    }\n}\n<\/pre>\n<p>This ensures that sensitive or dynamic pages are always fetched fresh from your backend.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Setting up a Varnish cache VPS configuration is one of the most effective ways to boost your website&#8217;s performance and reduce the load on your server. By acting as a high-performance intermediary between your visitors and your web server, Varnish can handle thousands of requests per second with minimal resource usage. Whether you are running a small blog or a large e-commerce platform, the steps outlined in this guide will help you get Varnish up and running quickly and efficiently. With proper configuration and fine-tuning, you will notice a dramatic improvement in page load speeds, user experience, and ultimately, your search engine visibility.<\/p>\n<p><\/body><br \/>\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Set Up Varnish Cache on Your VPS<\/p>\n<p>How to Set Up Varnish Cache on Your VPS<\/p>\n<p>If you are running a website on a virtual private server and struggling with slow load times or high server load, implementing a Varnish cache VPS setup could be the solution you have been looking for. Varnish Cach<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mbp_gutenberg_autopost":false,"footnotes":""},"categories":[147],"tags":[],"class_list":["post-16068","post","type-post","status-publish","format-standard","category-general"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/16068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/comments?post=16068"}],"version-history":[{"count":0,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/16068\/revisions"}],"wp:attachment":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/media?parent=16068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/categories?post=16068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/tags?post=16068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}