Using nginx to serve static content with Evergreen

Posted on Sun 04 October 2009 in Libraries

Update 2009-10-04 Added a title to the post; oops!

A long time ago, when I discovered that Evergreen was chewing up and spitting out Apache backends at a furious pace because Apache was being used to serve up static content like CSS, JavaScript, and image files, I suggested that using nginx to serve up the static content and proxying the dynamic requests to Apache would be a good solution to a number of problems we were facing. Here we are, five months later, and I've managed to put in a few hours tonight (amidst stomach-wrenching laughter at SNL's "Threw it on the ground" tune) to get a proof of concept configuration working on the Ubuntu 9.10 beta release.

The following nginx configuration hasn't been tested in a production environment yet, and isn't tuned beyond the defaults that ship with Ubuntu Karmic, but it works on my laptop in a virtual image for both regular HTTP and SSL requests - so what could possibly go wrong?

Steps to get this working on Ubuntu Karmic, assuming that nginx and Apache are running on the same server:

  1. Install nginx: sudo aptitude install nginx
  2. Copy the configuration file, changing "192.168.69.107" to match your server's IP address or host name, into a file called /etc/nginx/sites-available/evergreen and create a symbolic link to the file at /etc/nginx/sites-enabled/evergreen
  3. Modify /etc/apache2/ports.conf to change port 80 to 9080 and port 443 to 9443.
  4. Modify /etc/apache2/eg_vhost.conf to change the "Listen 443" directive to "Listen 9443"
  5. Restart nginx and Apache to put the new configuration in place
  6. Enjoy!

As I said, there's probably plenty of room for improvement; I have only a few hours of experimentation with nginx under my belt at this point. But assuming no showstoppers turn up after further testing, I would expect to see this going into production in Conifer sooner rather than later, and potentially becoming a standard part of any production Evergreen system.