implementing-varnish-cache

implementing-varnish-cache

Implementing Varnish Cache

.. contents::

Install varnish

.. code-block:: bash

sudo apt-get install varnish

Make varnish listen to port 80

Also disable the varnish admin port

.. code-block:: bash

sudo cp -p /etc/default/varnish /etc/default/varnish.ORIG sudo vim /etc/default/varnish

diff /etc/default/varnish /etc/default/varnish.ORIG 40c40,41 < DAEMON_OPTS=“-a :80
— > DAEMON_OPTS=”-a :6081
> -T localhost:6082

Make Apache2 vhosts listen to port 8080

.. code-block:: bash

cp -p /etc/apache2/ports.conf /etc/apache2/ports.conf.ORIG sudo vim /etc/apache2/ports.conf diff /etc/apache2/ports.conf /etc/apache2/ports.conf.ORIG 8c8 < NameVirtualHost :8080 — > NameVirtualHost :80 10c10 < Listen 8080 — > Listen 80

Now edit all the vhost files with two commands:

.. code-block:: bash

cd /etc/apache2/sites-available sudo perl -pi -w -e ‘s/:80/:8080/g;’ *

The above command performs a search and replace on every file in the directory changing :80 to :8080

Restart Daemons

.. code-block:: bash

sudo service apache2 restart sudo service varnish restart