Varnish is an open source reverse HTTP proxy, an web accelerator typically run in front of web servers such as Apache or Nginx. Designed to increase the performance of busy, dynamic web sites in case of high server traffic.
In this article, i will explain how to install and configure Varnish as a front-end to an Apache web server on Centos 7 .
Environment
– A Centos 7 Server running Apache
Step 1 – Add EPEL Repository
Before installing Varnish we need to install the EPEL Release using the follow command
[root@webserver ~]# yum install epel-release -y
Step 2 – Install Varnish
[root@webserver ~]# yum update -y [root@webserver ~]# yum install varnish -y
After Installing Varnish we need to start and enable Varnish to start at boot using the following commands
[root@webserver ~]# systemctl enable varnish [root@webserver ~]# systemctl start varnish
Step 3 – Varnish Configuration
By default Varnish listens on port 6081. So we need to change port 6081 to 80 by editing the varnish.params config file.
[root@webserver ~]# vi /etc/varnish/varnish.params
Change VARNISH_LISTEN_PORT from 6081 to 80:
VARNISH_LISTEN_PORT=80
Now open the default.vcl file and configure the port of your backend web server :
[root@webserver ~]# vi /etc/varnish/default.vcl
Change the port to 8080.
backend default { .host = "127.0.0.1"; .port = "8080"; }
Step 4 – Apache Configuration
By default Apache listens on port 80. Now, we need to replace the default Apache port to 8080.
[root@webserver ~]# vi /etc/httpd/conf/httpd.conf
Listen 8080
After that we need to restart httpd and varnish using the following commands
[root@webserver ~]# systemctl restart httpd [root@webserver ~]# systemctl restart varnish
Step 5 – Test Varnish
To verify that Varnish is on and working properly, you can use the curl command to view the HTTP header:
[root@webserver ~]# curl -I http://localhost
You should get an output like this
HTTP/1.1 200 OK Date: Mon, 14 Nov 2016 12:21:07 GMT Server: Apache Content-Length: 108 Content-Type: text/html; charset=UTF-8 X-Varnish: 32807 Age: 0 Via: 1.1 varnish-v4 Connection: keep-alive
PS. If you like this post please share it with your friends on the social networks using the buttons below.Thanks.