Follow the below steps to configure the Varnish.
(a) This is how to setup Varnish. You have to follow few steps to configure Varnish so your server will be faster than before it your visitors will feel how fast it loads. What are you goint todo? All you have to do is making Varnish to run on port 80 while Apache on port 8080. First configuration file you need to edit is located at “/etc/default/varnish”. use Vi to edit it.
vi /etc/default/varnish
Now look for these lines there under “Alternative 2″:
DAEMON_OPTS="-a :6081 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
Now edit those lines to match following to make it works in port 80:
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
Once done save it and exit.
(b) As you will use Varnish Configuration Alternative 2 (with VCL), so you have to also the default.vcl file which tells varnish where to look for the webserver content (in this case is to fetch from Apache in port 8080). This step is also called as to set the backend server. Use Vi again to edit it.
vi /etc/varnish/default.vcl
Now you’ll see some lines like below. If not, edit it to match as following:
backend default {
.host = "127.0.0.1";
.port = "8080";
}
The config above says that Apache as the backend server is available on localhost at port 8080 and Varnish will run in front of it listening on port 80 that previously used by Apache.
Now you’ve setup Varnish configuration to work on port 80. Next step, you have to also make Apache to work on port 8080. Without doing this step, Apache will still running on port 80 and so Varnish. Now edit Apache port setting and set it listen to port 8080 instead of 80
find “NameVirtualHost” and “Listen” lines and replace 80 with 8080.
Find:
NameVirtualHost 127.0.0.1:80
Listen 127.0.0.1:80
edit it to:
NameVirtualHost 127.0.0.1:8080
Listen 127.0.0.1:8080
(c) Now edit the virtual hosts file for your site’s domain name (in case if you host more than one website in your server). I assume you knew about virtualhost file and how to set it. So edit the conf file and search for VirtualHost and set the port no as 8080, Like below.
<VirtualHost *:8080>
(d) Restarte the apache and varnish service, Like below.
service apache2 restart
service varnish restart
That's It!
Please let me know If you have any doubt.