How to Install And Configure Varnish

cPanel 3.4.2018 No Comments

How to Install And Configure Varnish

 

Before installing Varnish, you will have to install the EPEL repository. You can do this by running the following command:

yum install -y epel-release
yum install -y varnish
systemctl start varnish
systemctl enable varnish
systemctl status varnish
varnishd -V

Configure Varnish

The Varnish configuration file will be located in the /etc/varnish directory in CentOS 7. To make Varnish work in front of Apache, you will need to set up some basic configurations.

By default Varnish listens on port 6081. You will need to change port 6081 to 80 so that website requests access the Varnish cache first. You can do this by editing the varnish.params config file.

sudo nano /etc/varnish/varnish.params

Change VARNISH_LISTEN_PORT from 6081 to 80:

VARNISH_LISTEN_PORT=80
Save the file, then open the default.vcl file. This file tells varnish to look for the server content:

sudo nano /etc/varnish/default.vcl

Tell Varnish to get the content on port 8080.

backend default {
.host = “127.0.0.1”;(Here replace 127.0.0.1 with server IP)
.port = “8080”;
}

Configure Litespeed to work with Varnish

Go to Home » Plugins » LiteSpeed Web Server Plugin >> Change LiteSpeed Port Offset >> 8000, litespeed will listen om port 8080

Note:- Port offset allows you to run Apache and LiteSpeed in parallel by running LiteSpeed on a separate port.
For example, if Apache is running on port 80 and the LiteSpeed port offset is 2000, then you will be able to access LiteSpeed-powered web pages on port 2080.

Restart varnish and litespeed service

Test Varnish

curl -I http://localhost
HTTP/1.1 200 OK
Last-Modified: Tue, 30 Aug 2016 17:01:17 GMT
Content-Type: text/html
Content-Length: 111
Date: Tue, 03 Jan 2017 07:42:10 GMT
Server: LiteSpeed
X-Varnish: 7
Age: 0
Via: 1.1 varnish-v4
Connection: keep-alive

eLite Server Management
 We Specialize In cPanel Server Management
Affordable 24/7 Technical Support Company
Manage Dedicated Servers

 

Leave a Reply