For those of you who didn’t know, Varnish Cache is a powerful open source HTTP accelerator that can be installed in front of any Webserver such as Apache or Nginx. Varnish Cache can improve overall performance of your web server by caching contents. The Varnish cache stores the copy of user request’s and serves the same page when the user revisits the webpage. It makes your website really fast and accelerate your web site performance up-to 300 – 1000x (means 80% or more).
This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you through the step by step installation Varnish Cache 4 on CentOS 7.
Step 1. First, you need to enable EPEL repository on your system.
## RHEL/CentOS 7 64-Bit ##
# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
# rpm -ivh epel-release-7-5.noarch.rpm
Step 2. Install Varnish using Yum command.
Start varnish and make varnish start at boot:
To check the status of varnish, run the following command:
Step 3. Configuring Varnish.
Edit the Varnish configuration under /etc/varnish:
### nano varnish.params
# Default address and port to bind to. Blank address means all IPv4
# and IPv6 interfaces, otherwise specify a host name, an IPv4 dotted
# quad, or an IPv6 address in brackets.
# Admin interface listen address and port
### nano default.vcl
# Default backend definition. Set this to point to your content server.
Edit apache web server configuration and change listen port to 8080:
### nano /etc/httpd/conf/httpd.conf
Edit firewall to allow the http service:
Restart the Apache and Varnish service for the changes to take effect:
Step 4. Testing Varnish.
The test consists in making a HTTP request via curl and verifying that it is handled by Varnish:
[email@example.com]# curl -I 192.168.146.131
Congratulation’s! You have successfully installed varnish cache. Thanks for using this tutorial for installing Varnish 4 on CentOS 7 system.