Subscribe via

Setting up a FreeBSD 6.2 Web Server: Proxy Caching (Part 7)

Thaya Kareeson

Okay I lied, eAccelerator gives a pretty darn high ROI, but setting up a proxy cache gives a comparable or higher ROI. I chose to use Varnish as my proxy cache.

Once installed, Varnish will keep a cache of all objects requested by internet users (e.g. post-generated PHP pages, CSS, javascripts, images) with the goal of off-loading some work from your web server (remember: we won’t want big Apache to do the work only if it has to). Also Varnish takes full advantage of the OS’s virtual memory and advanced I/O features on FreeBSD 6.x making it the optimal choice for my setup.

There were many confusing instructions on the web about how to configure Varnish. Here are the steps I took to setting up Varnish for a signal machine running both Varnish and the web server:

1) Port install Varnish.

cd /usr/ports/www/varnish/; make install clean

2) Change Apache’s port to 8080 by modifying this line in /usr/local/etc/apache/httpd.conf

Listen 8080

3) Restart Apache

/usr/local/etc/rc.d/apache22 restart

4) Start the Varnish daemon. Substitute the IP below with your machine’s internal network IP address. If you are hosting at home, it is most likely 192.168.0.* but you can run ifconfig to find out what it is.

varnishd -a <your-machines-internal-ip-address>:80 -b localhost:8080

That’s it! From now, all requests on port 80 should now be routed through the Varnish proxy cache. A proxy cache miss will seemlessly make Apache calls to serve the internet user without the user ever knowing it! A proxy cache hit would not access Apache (and therefore not access MySQL) lessening your machine CPU usage and increasing the speed & efficiency of serving objects to user.

Save and Share
Del.icio.us
StumbleUpon
Digg
Reddit

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Currently experiencing problems with Intense Debate commenting system. Please make sure your browser's Javascript is enabled and try again later.