In this tutorial we’ll learn how to install Varnish on CentOS 7. We will also install and configure its prerequisites. Varnish is a proxy and cache, or HTTP accelerator, designed to improve performance for busy, dynamic web sites. By redirecting traffic to static pages, varnish reduces the number of dynamic page calls, thus reducing load. Varnish is designed for content-heavy dynamic web sites as well as heavily consumed APIs. In contrast to other web accelerators, such as Squid, or Apache and nginx, which are primarily origin servers, Varnish was designed as an HTTP accelerator.
I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.
Install Varnish on CentOS 7
Step 1. First, ensure your system is fully up-to-date by running the following:
yum -y update yum install epel-release
Step 2. Installing Varnish Cache.
Install varnish using yum command:
yum -y install varnish
After installation, you will need to start Varnish and enable it to start on boot:
sudo systemctl start varnish sudo systemctl enable varnish
Check the version of Varnish that is running:
Step 3. Configuring Varnish Cache.
Edit default configuration file of Varnish Cache, varnish.params using your favorite text editor.
Change VARNISH_LISTEN_PORT from 6081 to 80:
Now edit Apache configuration file:
Then look for the line that says “Listen 80” and change it to “Listen 8080”.
Now restart Apache at first so the webserver run on port 8080 leaving port 80 being usable by Varnish:
systemctl restart httpd.service systemctl restart varnish.service
Step 4. Verifying Varnish Cache.
You can easily verify if Varnish is running by running the following command:
curl -I localhost
You should see the output something like this:
HTTP/1.1 200 OK Date: Wed, 16 Dec 2017 9:24:07 GMT Server: Apache/2.4.6 (CentOS) Last-Modified: Fri, 16 Oct 2017 10:36:53 GMT ETag: "6c-5211cdbf61c14" Content-Length: 108 Content-Type: text/html; charset=UTF-8 X-Varnish: 32770 Age: 0 Via: 1.1 varnish-v4 Connection: keep-alive
Congratulation’s! You have successfully install and configured Varnish cache on your CentOS 7 server. Thanks for using this tutorial for installing Varnish on CentOS 7 system.