home | talks | photos | about | resume | contact

This Site Brought to you By Nginx

As of today this site is being served using Nginx!

After spending a little bit of time messing around running lighttpd on some personal stuff at home I decided to give Nginx a whirl this weekend and it’s quite awesome. So awesome in-fact that I’m now working to totally replace Apache with Nginx (that’s no small tasks for 60+ sites).

Apache has served me well for more than six years while I did PHP development but now that I’m not really doing very much PHP work anymore and it has just become a pain to configure and maintain. For PHP work I ended up using Apache as a combination web/application server which, on reflection, doesn’t seem like it was such a great idea. Apache ended up taking lots of memory and the whole setup was comparatively fragile; if anything where to go wrong in PHP then the whole web server would fail to start.

I looked at lighttpd first as a candidate to replace Apache and for the most part I liked it but in the end Nginx was the winner. Probably the biggest reason to go with Nginx over lighttpd was that the configuration and the transition from Apache was easier than with lighttpd. Nginx has a very nice rewrite module and most of my apache rewrites where very simply transferred over as where all of my htpasswd files.

Out of the box the setup was pretty simple. There’s a slightly older version of nginx in the Ubuntu apt repository which is compiled with everything needed to get up and running. The PHP CGI version was setup to run as FastCGI out of the box as well. A small shell script to spawn PHP as the proper user and everything was pretty much good to go. The only annoying thing was that Ubuntu has opted to configure Nginx in the same way they do for Apache which separates your default server (vhost in Apache terms) from the main config which is dumb because you can’t really run the server at all without the default server so its not really something to be enabled or disabled. Otherwise it was a very smooth change.

My current setup has PHP running as a FastCGI application server with a pool of five processes communicating with Nginx over a Unix socket. Nginx runs two workers of its own on a dual-core server. The only things Nginx is currently handling aside from serving web requests are rewrites, some simple authentication and proxying back to Apache traffic for sites that haven’t been migrated yet. The setup seems to have cut memory usage on the box by nearly half.

The one thing that I’m going to miss is mod_dav_svn for Apache. I’m not sure if there is a suitable replacement for Nginx but I’m seriously considering transitioning all of my SVN stuff to Bazzar anyhow so this is probably a moot point.

Leave a Reply




DISCLAIMER: The opinions expressed on this website are mine and mine alone, they should not be interpreted as the views of my employers, past or present, my family, my church or my pets. Comments are the property of their posters and I can not be held accountable for those.