There are few things you need to do to install Varnish with Cpanel (WHM):
- Let Apache listen on port 8080 – you can do it by editing httpd.conf or directly in WHM: Tweak Settings menu -> set value of field Apache non-SSL IP/portto 8080 and Save settings
- install Varnish on your server:
Execute commands:
#install varnish repository
rpm -Uvh http://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release/varnish-release-3.0-1.el6.noarch.rpm
#yum installation of Varnish
yum install varnish
- Edit configuration of Varnish /etc/sysconfig/varnish and change value of VARNISH_LISTEN_PORT to 80
VARNISH_LISTEN_PORT=80
- Edit Varnish Config: /etc/varnish/default.vcl
Use following content (don’t forget to set correct IP address):
backend default {
.host = “50.28.31.120”;
.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;
}
}
- Now start Varnish service on your server:
chkconfig varnish on
service varnish start
- Now you are all set.
Now you can monitor your varnish cache e.g. with commandline tool: varnishstat
if you want to make changes to your varnish configuration, test your configuration changes before restarting varnish with following command:
varnishd -C -f /etc/varnish/default.vcl