Varnish Cache is an open source web application accelerator. Vanish stores all the cache files in memory which will reduce the response time. This caching tool will increase application scalability. Varnish caches all the pages produced by the application. This doesn’t need to run the code again till we flush or invalidate varnish cache. This will reduce the server load and thus increases reliability.

Since varnish is a caching proxy. The request go to varnish first and then it decides whether to server cached copy of the page or forward that request to the application

Configure Apache2 on Ubuntu server

If your server is running behind a Enterprise Firewall then make sure to open the Apache ports got http & https.

Update the default port (80) used by Apache in ports.conf file

Update the Listen from 80 to 8080. As we need to use port 80 for varnish

Also update the default Virtualhost configuration file

Validate the config files and restart Apache

Since varnish is available in ubuntu repositories we can use following commands to install

Enable the handshake with the Apache for this to work on the Apache server. First create a backup of the default varnish configuration file

Make sure that backend is pointing to the correct server IP and port. In our case, both varnish and apache is on the same server and apache listening port is 8080, this configuration is fine

Enable Varnish to listen on the default HTTP port (80). This can be set in the /etc/default/varnish file

Find the following DAEMON_OPTS line which is uncommented already in the file. DAEMON_OPTS=”-a :6081 \ to DAEMON_OPTS=”-a :80 \

 Update Varnish service to the new port

locate the ExecStart line and update the port

Restart the Apache & Varnish service for change to take effect