Nginx from Apache


I'd heard about Nginx a couple of times duing my time at UCL. My co-worker had set it up as the front-end proxy to deal with all the static requests and have Apache do the heavy lifting. Now, when it comes to building things, its a good idea to stick with what you know and actually ship, so long as things aren't broken.

My apache setup was broken!

On occasion, it would just stop working, eating all the memory and being a pain in the arse. So instead, I thought I'd look into Nginx as a replacement. People I respect have said its good and I wanted to keep up to date.

So, I run two django instances, an SSL setup infront of mediawiki and this static blog, so a good selection of things to setup there. Virtual hosts, some way of running Python, PostGreSQL and basic security. Quite a lot to throw in, in a single afternoon.

However, it is wasn't for a change to my DNS I'd have most of it done by now! Unbelievable! I'm quite impressed. With the Django setup's, I released I needed something called fastcgi . Essentially, fastcgi allows a websever to grab info from another running process quickly through a socket. Django supports this out of the box so long as you have python-flup installed. So I ran easy_install and followed the instructions that I found [on the django page] ( It took me a while to find this out and I'd gone down other routes such as fastcgiwrap and similar which I discounted in the end. It means you need to run the script with a few flags and have a socket that is accessible by your Nginx user. Also, you need to run the as a Nginx user which helps. The setup for a Django page with Nginx can be found here but I needed to send a few extra variables before it would work fully. I found this out from Stack Overflow.

I needed to do this twice. Fortunately the virtual hosts setup is trivial and the Nginx Configuration Wiki will let you know how to do it. No problems there then.

SSL is quite easy two with just a couple of lines needed to do the full setup, since I had some certificates and keys from my apache setup anyway. I didn't get around to changing mediawiki because I wanted to change the DNS to make a more sensible URL for that site. It doesn't look like it'll be too hard though.

So far, Im quite impressed with how easy it's been. I havent changed any files around and all is well. Top job Nginx!