Thursday, October 30, 2014

How To Install and Configure Varnish 3 with Apache on Debian

How To Install and Configure Varnish 3 with Apache on Debian


About Varnish

Varnish is an HTTP accelerator designed for content-heavy dynamic web sites as well as heavily consumed APIs. In contrast to other web accelerators, such as Squid, which began life as a client-side cache, or Apache and nginx, which are primarily origin servers, Varnish was designed as an HTTP accelerator. Varnish is focused exclusively on HTTP, unlike other proxy servers that often support FTP, SMTP and other network protocols.


Setup

Apache and Varnish


apt-get install apache2

Step One—Install Varnish


The varnish site recommends installing the varnish package through their repository.


You can start that process by grabbing the repository:


curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add -

The next step is to add the repository to the list of apt sources. Go ahead and open up that file.


vim /etc/apt/sources.list

Once inside the file, add the varnish repository to the list of sources.


deb http://repo.varnish-cache.org/ubuntu/ lucid varnish-3.0

Save and exit.


Finally, update apt-get and install varnish.


apt-get update
apt-get install varnish

Step Two—Configure Varnish

Varnish will serve the content on port 80, while fetching it from apache which will run on port 8080.

vim /etc/default/varnish


DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"

Once you save and exit out of that file, open up the default.vcl file:


vim /etc/varnish/default.vcl

The configuration should like this:


backend default 
.host = "127.0.0.1";
.port = "8080";

if enbale esi


 sub vcl_fetch 
set beresp.do_esi = true; /* Do ESI processing */
set beresp.ttl = 24 h; /* Sets the TTL on the HTML above */

Step Three—Configure Apache


vim /etc/apache2/ports.conf

Change the port number for both the NameVirtualHost and the Listen line to port 8080, and the virtual host should only be accessible from the localhost. The configuration should look like this:


NameVirtualHost 127.0.0.1:8080
Listen 127.0.0.1:8080

Change these settings in the default virtual host


vim /etc/apache2/sites-available/default

<VirtualHost 127.0.0.1:8080>

Save and exit the file and proceed to restart Apache and Varnish.


service apache2 restart
service varnish restart

or manual start varnish


varnishd -f /etc/varnish/default.vcl -s malloc,128M -T 127.0.0.1:2000 -a 0.0.0.0:999 -d


How To Install and Configure Varnish 3 with Apache on Debian

No comments:

Post a Comment