What's new

Welcome to WebForum | Zimbabwe Web Hosting Forum.

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

Ask question

Ask questions and get answers from our community

Answer

Answer questions and become an expert on all topics.

Contact us

Get in touch with the site administrator directly.

Forum Group

Join the Forum Whatsapp group for daily updates.
  • Thanks for participating in our community, Discuss and Learn. All Forum members are allowed to create threads and posts. Resources posted here should be CLEAN and SAFE. Do not post “offensive” posts, links, or images. Remain respectful of other members at all times.

How to install Varnish on cPanel?

WebForum

Administrator
Staff member
Administrator
Moderator
Business
Joined
May 19, 2021
Messages
98
Reaction score
21
Points
8
Location
Bulawayo
Website
ecowebzim.com
A quick reminder on what varnish is.

Varnish is a web cache that runs on Linux, it listens on port 80 (the usual HTTP port) and connects to a web server such as Apache running on an alternate port on the server, such as 8080. Varnish stores/caches the copies of your pages and when requested by a visitor it serves those pre-built pages without having to process them over and over again.

Since Varnish listens on Port 80 (HTTP), we will first need to change the port for Apache running on our server. We will be changing the Apache port to 8080. To do this, login to your WHM as root, click on Tweak Settings from the sidebar, head over to the system tab and change the Apache Non-SSL port to 8080.

Screen-Shot-2015-01-22-at-4.13.03-pm.png

Now, we can proceed with the installation of Varnish. You need to be logged in as root via SSH. Type:

Install Varnish Repository

Code:
rpm -Uvh http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm

Install Varnish

Code:
yum install varnish

Once the installation completes, we will configure Varnish to listen on port 80.

Edit the file /etc/sysconfig/varnish using your preferred editor.

Code:
nano /etc/sysconfig/varnish

VARNISH_LISTEN_PORT=80

Varnish is not a web server, it is merely a proxy sitting in front of a web server such as Apache, this implies that you would still need to run Apache on an alternate port on your server (such as 8080) and varnish in turn connects to Apache on the backend and listens on port 80 in the front end.

We now need to configure Varnish to connect to Apache on port 8080. Type in the following:

Code:
cd /etc/varnish/

Code:
mv default.vcl default_bak.vcl

Code:
touch default.vcl #creating a new default config file

Code:
nano default.vcl

Paste the following code.

Code:
backend default {
.host = "<your server's IP address>";
.port = "8080";
}

sub vcl_recv {
if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
return(lookup);
}
}

# strip the cookie before the image is inserted into cache.

sub vcl_fetch {
if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
unset beresp.http.set-cookie;
}
}

Make sure you replace the <your server’s IP address> with the IP address of your server. Finally enter:

Code:
chkconfig varnish on

service varnish start

You can monitor the performance of your Varnish cache using the command line tool :

Code:
varnishstat

That is it, you now have varnish running on your server.
 

Forum statistics

Threads
114
Messages
175
Members
89
Latest member
denzel
shape1
shape2
shape3
shape4
shape5
shape6
Back
Top