Exploring Nginx

I recently needed to set up a new server to act pri­mar­ily as a web server. With Rackspace, this has a very easy begin­ning: choose the Gentoo image and cre­ate the server. Typically I run emerge –sync, emerge –avuDN @world (wait a while), revdep-rebuild, emerge –dep­clean –a, and python-updater in that order to make sure I have things up-to-date. There are some other clean up items that also need to be done since at least at this time the Rackspace image needs a bit of updat­ing but that is minor. While I waited for the ini­tial emerge @world I got busy and con­fig­ured the server secu­rity and other basic ser­vices the way I like.

I wanted to use Apache 2.4 since it is sup­pose to be bet­ter so I did a lot of research on installing and con­fig­ur­ing it. With a fresh server I had a fresh start. I have used php-fpm for a while now in my new servers and I thought based on some arti­cles on the Net it would be some­what triv­ial to get Apache 2.4 to work with php-fpm espe­cially with the new default event mpm. After a day of bang­ing my head against that wall I gave up, unin­stalled 2.4 and installed Apache 2.2 and quickly had it run­ning with three dif­fer­ent web sites.

But I wasn’t happy. As I researched the issues I was hav­ing with Apache 2.4 I kept see­ing things about Nginx (pro­nounced engine x). I know all the pos­i­tives that Nginx has espe­cially its per­for­mance ben­e­fits. It has a lot of good buzz. I have been intrigued by it for many years and seem to install it every so often but I never pull the trig­ger to switch.

I am com­fort­able with Apache but more impor­tantly, every time I try Nginx I run into major prob­lems. The biggest warn­ing that every­one seemed to say that Nginx was good for sin­gle host web sites but not for shared host­ing. Since I rarely set up a server that only serves a sin­gle web site Nginx seemed to be a no go for me. I also have never liked the lack of an equiv­a­lent to the .htac­cess file. It always seems that this leads to incom­pat­i­bil­ity with stan­dard CMS and web frameworks.

But, I decided to do some research to see if Nginx would work. After set­ting the USE flags I did a quick emerge –av nginx to com­pile and install it. After doing the basic con­fig­u­ra­tion to have Nginx work with php-fpm I checked the local­host install and was pleas­antly sur­prised that every­thing worked. After set­ting up the vir­tual host files for the three web sites I reloaded Nginx and was rather sur­prised again that all three sites, a WordPress site, a ZenCart site and a Joomla site worked. More impor­tantly, I started to grok Nginx con­fig­u­ra­tion and felt like there are some major behind the scenes advan­tages to Nginx. I have actively used the WordPress site for sev­eral days with­out problems.

I still have some other tests to run but so far Nginx has proved to be a good replace­ment for Apache where I pre­vi­ously found it lack­ing. I haven’t tested its per­for­mance against the Apache server, I will, but I have already noticed that it doesn’t take as much server resources as Apache did. And the major com­plaint about shared host­ing seems to be a non-issue for now. I may still need to switch back if I run into an issues that Apache can solve but Nginx can’t but for now, I am a reluc­tant for now convert.

Follow up: A Year Later

Well, I ended up hav­ing enough lit­tle issues that other than one site, Nginx has not really taken over for me. In fact, we had one site that kept hav­ing minor issues. Just for test­ing pur­poses, I switched it from Nginx to Apache and all the prob­lems went away. I believe it had to do with the rewrit­ing needs of the site. Although we noticed a minor per­for­mance hit, we never switched it back to Nginx, don’t fix what isn’t broke eh?

Tagged on: , , ,

Leave a Reply