You are reading

Varnish + Lighttpd

Posted: June 5, 2009 | By: TJ | In Technology | No comments yet

For a while now, I’ve wanted to implement a reverse proxy or http accelerator with Lighttpd. Two popular offerings are Squid and Varnish. After reading some of the architect notes, I decided to go with Varnish. Instead of installing from source, I used apt-get:

$ apt-get install varnish

The key is then setting up Varnish to listen on port 80 which will then proxy to your web server, in this case Lighttpd. Open up your lighttpd.conf file and change the server.port value:

server.port = 8080

Then force reload the new Lighttpd configuration:

$ /etc/init.d/lighttpd force-reload

Now you’ll have to stop varnishd, and reload it with the following command:

$ varnishd -a :80 -b 127.0.0.1:8080 -T 127.0.0.1:6082

This will proxy all requests from port 80 to 8080 which Lighttpd is now listening on. The -T flag is for the management interface. You can then manage Varnish by sending commands over this port to update the VCL file or just find cache status information. There are serveral flags you can use to define many options with Varnish; I recommend reading the man page for all the good stuff. Since I am using WordPress, I also found a great article with an example VCL file specifically for WordPress.

If you want to check if Varnish is doing it’s thing, you can take a look at the http header. You should see two obvious entries:

X-Varnish => 620759461
Via => 1.1 varnish

Leave your comment



Copyright © 2010. All rights reserved.

This blog is powered by WordPress and proudly hosted by (mt) Media Temple.