Is Drupal on nginx ready for prime time?

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

Hi,

Is nginx ready to run Drupal production sites with all the features usable?
or is it still a lot of trial and error to get it working??

Reason I ask is that I am looking at moving to php-fpm anyway and on a quick test have already had issues with clean URL's.. Since there is very little information around on running Apache with PHP-FPM and even less with Drupal as well it might be a time to look at nginx..

My concern is that I don't want to spend my life "tweaking" it every time I add a new module or want to enable a new feature..

I also want to make use of multisites and using Drupal core as a library by symlinking to a shared codebase.. Is it likely that these setups will ahve issues with nginx?

Is there an acknowledged config for running nginx drupal virtual servers?

Thanks..

Comments

Yes, no, no, and depends on

brianmercer's picture

Yes, no, no, and depends on what you mean by "acknowledged".

It's easiest to stick to Apache. If you want the advantages that nginx provides, then folks in this group are happy to help.

I agree with brianmercer. You

Fidelix's picture

I agree with brianmercer.

You will need to tweak, you will need to read.
perusio, omega8cc, brianmercer and some others have already reduced those 2 efforts by 70% for the drupal community, but you will still need to learn how different nginx is, and IMO that's something you can only figure out by yourself, testing.

I tell you this: The effort pays off. A lot.

Thanks for the feedback.. In

wipeout_dude's picture

Thanks for the feedback.. In the time since I posted the original message I have tried nginx on a development virtual server and after a bit of hair pulling have managed to get it to install and load a fresh drupal 7.10 site..

Maybe I should change the question to..

Are there any specific situations where nginx is a problem for drupal where solutions cant be found? (eg. specific common modules or libraries that cause problems)

One thing I haven't worked out is how to protect the "private" files directory because obviously the .htaccess file is not used.. Still digging.. :)

Check out perusio's config at

brianmercer's picture

Check out perusio's config at https://github.com/perusio/drupal-with-nginx

He includes this location that forbids external access to the private directory, but allows internal redirection for purposes such as x-send:

## Trying to access private files directly returns a 404.
    location ^~ /sites/default/files/private/ {
        internal;
    }

I favor placing the private directory outside the web root, which would make any protection unnecessary.

Wow.. That's a whole heap of

wipeout_dude's picture

Wow.. That's a whole heap of config that's going on there.. :)

Thanks for the link.. Think I am going to have to look through it all and see what its doing to get a better idea what its all doing..

I see in the readme its suggested as a "drop in" replacement for the default /etc/nginx directory.. Is this something you would suggest or would it be better to "build" a custom config just referencing perusio's config?

It's supposed to be a drop in

Fidelix's picture

It's supposed to be a drop in replacement, but it's not. You will have to remove a lot of lines from perusio's config if you want nginx to start properly, as he uses a lot of instructions for nginx modules that don't come on apt repositories, and you'd have to compile nginx with those modules yourself.

About the private directory, I agree with perusio's approach, as it makes his config a little more general, compatible with drupal's default setting, and easy to maintain.

Perusio's config is the best one around for Drupal that I found.

It has a bunch of unnecessary instructions for general setups (IT REALLY IS FOR HIGH PERFORMANCE, I'M NOT KIDDING), and it could be better organized, but that's something we (the community) have to help with suggestions and commits. He's done much, much more than sufficient already.

You don't need to

perusio's picture

remove anything. It depends. I've been so busy lately that I have yet to update the documentation :( There's a setup that is for high-performance. Soon I'll update it with authenticated user caching.

Brian and Filipe (Fidelix) already have given you a pretty good summary of the issues at hand. Just to add my $ .02.

Regarding Nginx and Drupal. It's more than ready IMHO. In fact, I think attachment to things like Varnish is slowing down adoption. Wordpress is moving much faster in that regard: wordpress.com runs Nginx exclusively.

There could be some tweaking. There's a zillion modules out there and some are bound to depend on specially crafted .htaccess files and such. If you have issues report them here. We'll help you sort out those issues. As usual when you're threading new ground there's some learning to be done. But you'll get back your investment with a generous interest. I've learned so much since I've headed down the Nginx path. This group has helped me a lot along the way.

Here on d.o we're stuck with Apache an Varnish. Which is hardly forward looking. I run the latest "dev" branch (which is pretty stable, never had issues with it, apart from an accept4() thing a long time ago) and use a some modules that are not standard. You can compile Nginx from source yourself or grab the source package and build the .deb.

This group is the place to be for Nginx and Drupal. We'll help you as much as we can to have you setup Nginx up and running. Bring it on & Happy New Year.

Thanks everyone.. I had

wipeout_dude's picture

Thanks everyone.. I had thought about a staged switch over but I have decided to switch over nginx in one hit using the config perusio has provided and some custom settings that I need.. The plan is to load it up with php-fpm tomorrow and see if I can get it all running for my 5 or so virtual hosts on my server including the one with SSL.. Should be a challenge but what better time to do it than New Years Day.. :)

I am sure there will be some bumps along the way but might as well jump in..

Thanks for the discussion and Happy New Year to all!!

The quickest way to try multisite

travisc's picture

with Nginx is is to use the Barracuda and Octopus scripts by Omega8cc http://drupal.org/project/barracuda, http://drupal.org/project/octopus, http://groups.drupal.org/boa. Follow the install instructions very carefully and you will have a completely configured Aegir/Nginx server up in around 15 minutes.

I'm running Debian6 on 512k Linode, and its works flawlessly. It's a bit slow on the D7 modules page, probably a 1k linode would help that. Omega8cc also offers this configuration running on SSD's which apparently, is up to 10 times faster then a standard drive.

You'll have to learn Aegir, and it may be seen as overkill for some projects, but i'm very pleased with the result so far.

Nginx is the way forward IMO. Check out the Drupal BORG https://getpantheon.com/news/inside-pantheon-drops

I had issues with the way

wipeout_dude's picture

I had issues with the way Aegir handled things like SSL and allocation of IP addresses so I abandoned it for production sites..

Nginx with php-fpm have been running my sites now for a few weeks and I am so far very happy with the result.. Committed memory usage has dropped significantly and php is quicker.. I am for the most part using the Drupal config published on the nginx wiki with one or two minor tweaks..

That config

perusio's picture

is broken in several ways:

  1. It uses an unnecessary rewrite.

  2. Uses PATH_INFO and Drupal doesn't use PATH_INFO. It's insecure and that's why it needs that ugly looking block with the ~ \..*/.*\.php.

  3. Doesn't restrict which PHP files can be acessed and allows direct access to them. People bring the bad habits
    from the Apache world to Nginx, which does it like this. Then they act surprised when their sites get hacked.

@wipeout_dude SSL and extra

omega8cc's picture

@wipeout_dude

SSL and extra IPs with Aegir can be very easy - see my comment here: http://groups.drupal.org/node/203398#comment-669668