Ramblings on the Bible, Family, Food, Programming and More

Exploring Nginx

I recent­ly need­ed to set up a new serv­er to act pri­mar­i­ly as a web serv­er. With Rackspace, this has a very easy begin­ning: choose the Gentoo image and cre­ate the serv­er. 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 oth­er 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 wait­ed for the ini­tial emerge @world I got busy and con­fig­ured the serv­er secu­ri­ty and oth­er basic ser­vices the way I like.

I want­ed 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 serv­er 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­cial­ly 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 quick­ly had it run­ning with three dif­fer­ent web sites.

But I wasn’t hap­py. 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­cial­ly 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 nev­er pull the trig­ger to switch.

I am com­fort­able with Apache but more impor­tant­ly, 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 serv­er that only serves a sin­gle web site Nginx seemed to be a no go for me. I also have nev­er liked the lack of an equiv­a­lent to the .htac­cess file. It always seems that this leads to incom­pat­i­bil­i­ty with stan­dard CMS and web frame­works.

But, I decid­ed 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­ant­ly sur­prised that every­thing worked. After set­ting up the vir­tu­al 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­tant­ly, I start­ed to grok Nginx con­fig­u­ra­tion and felt like there are some major behind the scenes advan­tages to Nginx. I have active­ly used the WordPress site for sev­er­al days with­out prob­lems.

I still have some oth­er tests to run but so far Nginx has proved to be a good replace­ment for Apache where I pre­vi­ous­ly found it lack­ing. I haven’t test­ed its per­for­mance against the Apache serv­er, I will, but I have already noticed that it doesn’t take as much serv­er 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 con­vert.

Follow up: A Year Later

Well, I end­ed up hav­ing enough lit­tle issues that oth­er than one site, Nginx has not real­ly tak­en over for me. In fact, we had one site that kept hav­ing minor issues. Just for test­ing pur­pos­es, 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 nev­er switched it back to Nginx, don’t fix what isn’t broke eh?