Before we begin with the setup of the varnish with Apache, let us know a bit about Varnish and then move ahead with configuration of varnish with apache with some examples that gives you an idea of basic settings for the server.
Varnish is an HTTP Accelerator that helps delivering content heavy dynamic website faster to the clients by storing the content on the memory of the server. So the performance of the sites even after using varnish is some what dependent on the hardware resources available with server machine.
We will begin with the installation of the varnish on the Linux Box along with apache and then configuring the same to deliver the content.
If you are on RHEL 5 or a compatible distribution, use:
Now change the port on the virtual host directive to
then restart the apache server using commands
sudo service apache2 restart on a debian based distribution.
sudo service httpd restart on a RHEL based distribution.
sudo service varnishd restart to restart varnish server.
To check the stats of varnish server at any time use command
To confirm if the page is being served from varnish or not you can check the response headers for headers Via: which would have a value like 1.1 varnish and presence of another http header X-Varnish. These confirm that the page being served is done through varnish or not.
Now to a basic configuration that may be required by most of the sites that is to skip some url's so that they are never served by varnish and only served by Apache.
For example if you have a site that has an admin interface you may not want the pages for admin to come from cache and want these to execute on server every time these are requested this can be done easily by changing the configuration on varnish.
In the VCL file overide a function vcl_recv which is called everytime varnish receives a request.