Page-level caching with Nginx

Since my last post on using Nginx to cache proxied content, they have added proper cache handling via their proxy_cache* directives. These are much more suitable for use, as they capture the HTTP response headers and also use more advanced Cache-Control checks.

To start, install the latest stable Nginx avaliable at http://wiki.nginx.org/NginxInstall .

Laptop DNS forwarding to DHCP DNS

I run bind9, a DNS server, on my Ubuntu laptop so that I can use more advanced local dns resolution than what /etc/hosts can provide, such as wildcard domain names.

The problem is that in order for me to be able to use that DNS server whilst being able to resolve internet domains at the same time used to require me to do two things:

  • Edit /etc/resolv.conf, and change nameserver to 127.0.0.1
  • Edit /etc/bind/named.conf.options, and add a forwarder to the nameserver IP that was previously in /etc/resolv.conf

Workaround so NetworkManager runs dhclient hooks

When I upgraded from Ubuntu 8.04 (Hardy) to Ubuntu 8.10 (Intrepid), a dhclient-exit-hook script I wrote no longer functioned.

dhclient-script was previously used by dhclient so that whenever the dhcp changed, it would reconfigure the interfaces, generate the /etc/resolv.conf, and run scripts who’s intention is to modify the /etc/resolv.conf file based on the dhcp settings. These scripts are located in the folders /etc/dhcp3/dhclient-enter-hooks.d/ and /etc/dhcp3/dhclient-exit-hooks.d/.

Reading up on the problem, thanks to perlhead on the Ubuntu Forums, it appears that since NetworkManager did the same function as dhclient-script, which got in the way of NetworkManager’s plugins, so dhclient-script was disabled.

Page-level caching with Nginx 0.6

In a further attempt to modify my websites so that they can withstand the Digg Effect, I have looked into getting Nginx, a lightweight http server, to perform page-level caching.

Nginx can act as a reverse proxy, sending any HTTP request sent to it to another web server. It can also store the response to file, which can later be served on future requests.

Update 2010-04-10 – Nginx >= 0.7 now has proxy_cache* directives, to do this in those versions, see Page-level caching with Nginx