Current status and stability of nginx with Drupal

Events happening in the community are now at Drupal community events on www.drupal.org.
davej's picture

Hi,

Forgive the newbie question but I hope this will be of use to others and help people decide whether nginx is for them.

I'm currently planning a new server and am considering using nginx in place of apache. I've been reading through several posts in this group and found some interesting discussion. What would be really useful though is to get a sense of the current status of support for nginx in Drupal, so that those in my position can make an informed decision about whether Drupal + nginx is currently solid, stable and well supported or experimental, bleeding-edge and only for the intrepid.

The impression I've got so far:

  • Drupal system requirements state "Drupal is being developed to be web server independent, but we have limited or no reports of successful use on web servers not listed here." - namely, Apache & IIS. http://drupal.org/requirements
  • A colleague writes:
    "At the drupalcon I went to (Szeged 2008), I asked the panel of performance experts what experience they had using light webservers like lighty, nginx etc... Their response was pretty much that they didn't think the performance benefits were worth the cost of running on a non-standard platform, and that they stuck with apache for this reason.
    My experience backs this up to some extent - we sometimes found that php didn't work exactly as documented when running under lighty - mainly things that involved how environment variables are set etc... None of these problems were insurmountable, but they definitely cost us some time working out why things weren't working the way they were supposed to."
  • I've seen reports of problems using nginx with Drupal, e.g.

    http://drupal.org/node/110224#comment-1908932
    http://drupal.org/node/671948#comment-3200472

  • php-fpm seems to be the preferred way to use PHP with nginx, however IIUC this requires either PHP 5.3, which several contrib modules don't support, or patching PHP 5.2 .
  • Despite the above, several people here seem to be using it successfully and supporting others.

So the overall impression I've got is that the current status is more towards the "experimental, bleeding-edge and only for the intrepid" end of the spectrum - is that accurate?

We're not trying to run busy sites on small VPSs so we don't need a super-lightweight setup, however we are looking at ways to avoid static content being served by bloated apache processes (we run several Drupal + CiviCRM sites and our httpd processes often reach 100M resident each on a 64-bit server, averaging around 70M). Varnish is one option, we're wondering if nginx might be another - but only if we're confident that it's solid, stable and well supported.

Thanks,

Dave

Comments

I'd say your analysis is

brianmercer's picture

I'd say your analysis is right on.

nginx has not been widely adopted as a primary web server by the Drupal community. So if you're looking for widely-supported, I'd have to say no, since the majority of Drupal server admins don't have experience with nginx.

nginx does seem to be catching on as a front end load balancer, proxy (caching or not), and static file server. For example, the new DrupalGardens.com service uses nginx in front with Varnish (and I bet apache) in back. So Acquia is comfortable using nginx for some things.

There's nothing wrong with using nginx as a front end static file server and as a proxy to Apache as a backend. nginx is designed to proxy to all sorts of backends.

Those two links don't really show a pattern of problems. I've never had an issue with password recovery. Managing php processes through spawn-fcgi/php-cgi did have some issues in the past, but most of us use php-fpm now and the process management is greatly superior. php-fpm is an official, supported part of php since 5.3.3 (though my ppa uses the same fpm code with 5.3.2), and I know of no issues of dying processes with the new code. The lack of php 5.3.x support in some contrib modules is not exactly an nginx issue.

Varnish has been a great solution for users of the Pantheon Mercury stack and it's a great project. However Varnish doesn't do everything nginx does such as serve static files directly, SSL encryption, gzip compression, geolocalisation, DoS evasion, etc.

If you need any help setting up a test system, be sure to stop back.

There's nothing wrong with

Garrett Albright's picture

There's nothing wrong with using nginx as a front end static file server and as a proxy to Apache as a backend.

I respectfully disagree. I think it's silly to run two daemons that are both capable of doing the same thing. Running nginx for static stuff and Apache for dynamic stuff is even sillier than running Apache for both, and we all know how silly that is.

Some say that the performance improvement of running Lighty or nginx instead of Apache isn't "worth it." Okay, but better performance isn't the only reason to not run Apache; there's also the fact that Apache can be a memory hog, and using nginx or Lighty instead can free up memory to run things which really can make a huge speed difference, like opcode caches. This is especially important if you are using a cheapo VPS account with limited RAM to serve your stuff, as I am.

Well nginx doesn't care what

brianmercer's picture

Well nginx doesn't care what you're using as a backend. nginx may be more popular as a front end to Mongrel serving Ruby on Rails than as a proxy to php. Having nginx up front has many advantages regardless of the backend you're using, so I'd say it's better to consider nginx separately from php-fpm.

I prefer php-fpm like you do (heck, I maintain an ubuntu package for it!). But in my opinion there's nothing "wrong" with using nginx and Apache-prefork/mod_php-5.2.x if it meets your needs. It's not going to hog memory because you're going to have keep-alives off in Apache and the Apache threads will die when they're done. There's no reason that an Apache-prefork thread will use much more memory than a php-fpm thread (though I can't say I've tested it).

I've never seen a serious technical comparison of the process management capability/scalability/reliability of php-fpm versus Apache-prefork/mod_php. I'd be very interested though.

Use combo

Daniel Norton's picture

I'm with Brian in that it doesn't have to be either/or: nginx is not a big challenge to use as a static/proxy front-end server.

I had problems with

hedac's picture

I had problems with imagecache and using nginx for static files and apache for php...
I want to try php-fpm since it's included now in php 5.3.3. I hope it does get fully official support in drupal soon

Nginx and PHP-FPM

randalls's picture

We run Nginx and PHP-FPM successfully. Sure it may not be used as widely as Apache and there may be a few bugs, which I feel are not really a show stopper, at least for us. I have found our drupal sites very stable, over 100+ days of uptime as I speak under moderate load.

As far as bleeding edge, I would not go as so far to say that. Nginx and PHP-FPM have been a stable platform and a good enough reason to kick apache mod_php to the curb.

Nginx has a very small, lightweight code base, and new releases come out frequently. There is a .7x series which is a bug fix release and is very stable. There is an .8x release, which I have not tried, but I have heard of people using this with some success.

There are a lot of features in php-fpm over Apache, like a good threading model. Say good bye to Apache prefork model that has dominated for over a decade. How about the ability to restart threads if they fail. And now that PHP-FPM has been incorporated into PHP, i think its popularity will only increase, so I highly doubt moving to this platform would leave you out in the cold.

Also consider the security of your site. Now you can run php as a separate user from your web server. This kind of privilege separation could be important.

Using php-fpm/nginx does not preclude you from using varnish as far as I know, so you can still use an extra layer of caching if needed. For our sites, we have found that Nginx/PHP-FPM and APC running on a system with lots of RAM makes our sites very responsive. If we could throw memcache into the mix, I bet we could see some more improvements.

Finally, I would like to also throw in HAProxy, which is a pretty robust load balancer that can help your sites scale better. Also throw in postgresql and one of the many replication options, you could have a site that would never fail, at least in theory. So even beyond page caching, there are other things you can do too. It just depends on where you have identified your bottlenecks.

I believe nginx can load

intel352's picture

I believe nginx can load balance as well, but I'm not familiar with HAProxy, so it (nginx) may not be as robust in that area.

LXMP is a stable stack

omega8cc's picture

We are using Aegir with Nginx in production (hosted Drupal SaaS, not just our website) for over a year and I never used it with Apache. Furthermore, we are using Nginx with php-fpm in production (hosting) since 2007.

Nginx

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: