Debian Tutorials

Debian Tutorials


Step by step tutorials showing you how to install and configure various applications and services on Debian based Linux distros.

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories


Installing and configuring Varnish HTTP accelerator

Ástþór IPÁstþór IP

Varnish is a state of the art web accelerator. Its mission is to sit in front of a web server an cache the content. It makes your web site go fast.

1. Install Varnish

apt-get install varnish

2. Configure the backend (pico /etc/varnish/default.vcl)

backend default {
set backend.host = "157.166.224.26";
set backend.port = "80";
}

This will be the server containing the actual web site published to the users. I’m using the IP address for cnn.com for testing.

3. Configure deamon options for varnish to use the default.vcl (pico /etc/default/varnish)

Comment out the following lines: (lines 21 – 25)

#DAEMON_OPTS="-a :6081 \
# -T localhost:6082 \
# -b localhost:8080 \
# -u varnish -g varnish \
# -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"

Remove the comment blocks from these lines: (34 – 37)

DAEMON_OPTS="-a :6081 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"

By default, Varnish listens on port 6081 as specified in the -a parameter but for production you probably want to use port 80.

4. Restart Varnish

/etc/init.d/varnish restart

5. Test by entering this location in a web browser: http://yourserver:6081.

Replace yourserver with your server’s hostname or IP address

This is just a simple setup but you can set up multiple backends and do some advanced configurations. Here’s the Varnish documentation

Comments 1
  • Matt Smith
    Posted on

    Matt Smith Matt Smith

    Author

    On Ubuntu 11.04 I had to add START=yes at the top of /etc/default/varnish otherwise I got;

    * Not starting HTTP accelerator varnished [OK]

    when trying to start varnish