Subscribe via

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

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.

8 Responses to “Setting up a FreeBSD 6.2 Web Server: Proxy Caching (Part 7)”

[go to last comment]
  1. Do you add
    enable_varnish=”yes” to rc.conf too??
    or is it varnishd

  2. p.s. you should have another tag that says LAMP ๐Ÿ™‚

  3. i just saw the css changed in front of my eyes lol
    you are working on the first post thing right ??? lol

  4. and these two magic sentences too

    varnishd_flags=”-a 192.168.x.x:80 -b localhost:8080″


  5. Ty Bone

    Thanks Mek from for the rc.conf settings! This was the gap I’ve been trying to fill for ages!

  6. Ty Bone

    Small correction, varnishd_enabled=โ€yesโ€ should be varnishd_enable=โ€yesโ€ (without the ‘d’).

  7. Recapping: Setting up a FreeBSD 6.2 Web Server « OMNINOGGIN

    […] Proxy Caching […]

  8. Setting up a FreeBSD 6.2 Web Server: Optimizing PHP (Part 6) | OMNINOGGIN

    […] time by 25%! But if that’s still not fast enough for you, I will show you how to do Proxy Caching next. ids.push(58); if (!sz_post_config_params){var sz_post_config_params = new Array();} […]

[go to first comment]