It was suggested at the System requirements discussion that Nginx could potentially be a supported web server for Drupal.

I'm opening this thread to:

  • Discuss if we even want to support Nginx as a web server.
  • Patch INSTALL.txt to help installing Drupal on Nginx
  • Add example Nginx config files to Drupal

Comments

skolesnyk’s picture

I'm all in favor of supporting Nginx as a webserver for Drupal. And specifically not as a static content proxy in front of Apache but regular webserver via fast-cgi interface with php-fpm for PHP processing.

It works much faster and requires less resources then Apache-PHP combo.

Not so recent Nginx for Drupal conf files are here https://github.com/yhager/nginx_drupal/tree/master/conf

Also here https://github.com/omega8cc/nginx-for-drupal/tree/master/standalone it's promised that another conf will be available this very summer.

bibo’s picture

Nginx is already used on a lot of Drupal sites (definitely more than Drupal + IIS!), so it's a bit weird it's not even mentioned on the requirements-page (excluding comments).

I'm not too familiar with nginx yet, but I'll be following this issue.

webchick’s picture

Yeah, if someone has familiarity with this and wants to take it on, I think we'd gladly welcome documentation improvements to tell folks how to use Nginx with Drupal.

zserno’s picture

Hint: the fine folks over at the MNPP project (Mac + Nginx + Percona + PHP, a high performance webserver) already created a basic nginx config file for Drupal. See: https://github.com/jyr/MNPP/blob/master/conf/nginx/common/drupal
I've tested it and works fine with Drupal 6 and 7 so this could be a good starting point for this awesome issue.

thamas’s picture

There is a wiki page at nginx.org dedicated to Drupal. It can be useful too: http://wiki.nginx.org/Drupal

perusio’s picture

That config is hardly a nginx style config. It uses a lot of vices from mod_rewrite. For example, in Drupal 7 there's no need for any rewrite. Not even in Drupal 6 unless you rely on custom_url_rewrite_outbound, like OpenAtrium and ManagingNews do. Also it exists a Nginx group at g.d.o. It already has some history and is neighboring 390 members.

thamas’s picture

Thanks for commenting and mentioning the nginx group, here is the link: http://groups.drupal.org/nginx :o)

perusio’s picture

Drupal doesn't use PATH_INFO. Furthermore by making use of it you could be exposing yourself to the infamous cgi.fix_pathinfo vuln if your forget to set to 0.

thamas’s picture

NGINX–Drupal project at github: https://github.com/yhager/nginx_drupal (link via Denes.Szabo)

Coornail’s picture

I think that the next step is to gather what the example config file should provide:

  • Clean urls
  • Protect files and directories from prying eyes
  • Serve compressed css/js files if available

Thoughts?

perusio’s picture

I'll throw my config on the ring (the docs need updating) and let the "market" sort out while having the freedom to choose: https://github.com/perusio/drupal-with-nginx ;)

EDanee’s picture

Hi guys,

thamas mentioned this topic to me.
I current use nginx - not as a proxy - with php to serve a few (~80) domains, many of them are drupal based.

Due to the increased resource needs we have to upgrade our server, and I also took a closer look on the nginx configuration.

I think perusio's setup is a pretty good setup. I serves as a basis for my final settings as well.
You can find it here:
https://github.com/perusio/drupal-with-nginx

Daniel

Fidelix’s picture

I use perusio's setup too.

There are some things I'd change (like better organization of included configuration files), and some things I'd remove, at least for a more general nginx setup instead of a high performance (like perusio's repository)

But it's definitely the best start if comparing to other drupal setups out there.

JamesAn’s picture

I'll toss myself in here too. I've been running nginx + FastCGI for Drupal for almost 2 years now, before nginx made it to a 1.0 release this April and before Drupal 7. After moving from Apache config files to the nginx syntax, I haven't had any issues deploying Drupal websites running on nginx.

The config file set up I use needs some serious updating. I'll try to scrounge some time to give my opinion on some of the sample config files floated around here.

shp’s picture

Subscribing... Must-have feature!

fuzzy76’s picture

After trying out Perusios setup I really see the difficulty of this setup. If you don't have the same version of NGINX, you are in for a lot of pain. Error messages all over the places for unsupported configuration directives, and just commenting them out is not enough, as it breaks a lot of functionality. I'm not trying to belittle Perusios work, he has done a great job, I think it might just be a sign that the configuration syntax for NGINX isn't quite mature enough, unless we aim for a minimum version far above 1 (which isn't available in the most common server distro releases yet (Ubuntu 10.04 LTS being a good example).

Fidelix’s picture

fuzzy76, you are wrong.

Commenting perusio's config directives does not break functionality that is present on the old versions of nginx, except maybe for the limit_conn directive, that can help mitigate DOS attacks. Its syntax has changed since 0.8.

Saying nginx's configuration syntax is not mature because you tried perusio's config and it didn't work right away is lazy and wrong.
Try getting an advanced and customized apache configuration and pasting on a fresh apache installation, and you'll see what's not mature, you'll see what's non-standardized syntax.

Perusio's setup is tuned for his needs, and for overall high performance requirements, and it assumes you are not a newbie that doesn't know how to compile nginx from source.
Thus, his configuration, which is not for newbies that only know how to use vanilla apache, is far from adequate for a general-use config, even more far from being adequate as an official config.

A configuration that's supposed to be general/official would work across all versions of nginx, would have a lot less files, a lot less directives. And that is achievable with nginx's syntax.

The thing is, perusio's config doesn't deal only with what apache's .htaccess deal. It deals with a LOOOOT more stuff like php-fpm pools/instances, load-balancing, bit-streaming for video/audio, reverse-proxy caching (almost like varnish) with Microcache, security considerations, filtering of bad bots/bad requests, crack-attack mitigation, and a LOT more stuff that drupal's standard .htaccess doesn't deal with. So yeah, it's not for the average cpanel/apache user trying to get a little speed boost.

Don't blame nginx's configuration syntax for that.

perusio’s picture

In fact you're wrong, completely wrong. It's not related to my config, but rather to Nginx config language. In fact is IMHO lightyears ahead of Apache:

  1. It's mostly declarative: little space for side-effects and unpleasant surprises.
  2. It follows a C like syntax instead of a braindead XML like syntax (Apache).
  3. It's clearer in the sense that the several contexts are clear.
  4. It's much less verbose.

Now my config is not a minimal config. It tries to provide as much as possible of the features that Nginx offers.

If you're investing time in Nginx then why not take advantage of the many things it has to offer?

The fact is that most people never bother with the intricacies of Apache, because there are several layers of indirection provided by the out-of-the-box config. The price you pay is that now you're in sort of a blackbox.

xtfer’s picture

Having tried both Perusio's work and the config provided on the Nginx wiki, I can say that, unless you know what you are doing, the later is far easier, and I usually recommend people use that. That goes doubly so if you are not on the latest version of Nginx.

Its not particularly relevant why that is the case. If we want provide "support" for Nginx, arguably we should support the minimum configuration. The question is somewhat moot, however, as support for Nginx is not the same as Apache, where a file can be provided in the install and it just "works".

So what does "support" actually mean?

perusio’s picture

You shouldn't recommend a config that doesn't constrain PHP execution. That config is broken in several places.

See: http://wiki.nginx.org/Pitfalls#Passing_Uncontrolled_Requests_to_PHP and http://groups.drupal.org/node/232023#comment-771848

Support yes, but taking all aspects in consideration.

xtfer’s picture

@perusio, Like I said, somewhat beside the point. There must be some middle ground somewhere, a minimum safe configuration, but it's largely irrelevant what that configuration is, as Drupal cannot provide it.

Unless we dump a .conf file in a directory somewhere and tell people to delete it once they've copied it to their nginx configuration, I can't see a way to "support" nginx in any useful way.

But, while we are on the subject, if the configuration is not safe, what is required to make it safe. In other words, what is a minimal safe configuration?

perusio’s picture

You could create a drush command/module that checks your current Drupal setup and suggests a config. Checking the setup on the Nginx side is not easy because there's no server side API to get information about it, like in Apache. Minimal:

  1. safe config: by default only index.php is invoked. In D7 through a named location, in D6 with an exact internal location.
  2. imagecache support

Possible addons: cron.php and web based updates support.

jhodgdon’s picture

Component: documentation » base system

This is no longer a Documentation issue.

Fidelix’s picture

Component: base system » documentation

Instead of providing drush stuff, there could, maybe, be an official, community-supported configuration, for general-use.
So this would be documentation indeed.

chx’s picture

Based on postgresql experience if people want this to be officially supported IMO we need about 5-6 people who would pledge to test and bugfix D7 and D8 with nginx for the next about five years. Aside from that, of course, please write handbook pages and provide example configs.

I see no reason why D8 wouldnt work out of the box as long as fastcgi_param REQUEST_URI $request_uri is passed. But it's not a focus for any of us, so we need people who do focus on this.

perusio’s picture

@chx You can count on me. And I think that we'll find the remaining testers at the Nginx group easily.

RedRat’s picture

I'm using Drupal 6 and 7 with Nginx for more than a year and can test supposed configurations on my servers.

Andre-B’s picture

@chx I pledge to test nginx configurations in a high load environment. I can write documentation for this as well.

Fidelix’s picture

I pledge as well.

Anonymous’s picture

I can also commit to testing and bugfixing for Nginx. I've used Nginx for a little over a year and deploy it on the high availability hosting platforms that I provide.

xtfer’s picture

I run a couple of nginx servers, and can test.

jhodgdon’s picture

Component: documentation » other
Issue tags: +Needs issue summary update

I'm changing the component of this issue because it really isn't a documentation issue at all.

Actually, I'm not even sure what "support Nginx" means... Maybe someone who is familiar with what it would entail could click "Edit" at the top of this page and create a standard issue summary that outlines what it would mean -- what changes would need to be made to Drupal to support Nginx, what additional files would need to be added to the distribution, etc.? If it's just a matter of saying "we support Nginx", that's one thing, or saying "we have tested Drupal on Nginx and everything works", that's another thing, or "we provide the files and instructions needed to run Nginx on Drupal", that's yet another thing.

Thanks!

mitchell’s picture

Title: Add support for Nginx web server » Add Nginx to web server system requirements

I use Nginx and got started on this. Here's what I did to start this off:

  • Moved each section in the requirements to child-pages and set up aliases
  • Added Nginx to the requirements page and wrote a small description on the web server page
  • Linked to the setting up Clean URLs docs for Nginx to match the Apache info
  • Set Nginx's version minimum based on an inference and reference from #1498774-5: Minimum Nginx version supported? and #25
  • Migrated info specific to PHP from /requirements to /requirements/php and opened #1783110: Clean up PHP requirements documentation page in order to also add PHP-FPM info

I agree that adding info on configuring Nginx would be very helpful and pertinent to this task. http://groups.drupal.org/nginx probably has some good info, and this is the guide I normally use: Installing Nginx With PHP-FPM And MySQL Support On Ubuntu 12.04 LTS.

After we get the language of these docs together, I suppose we could then add a follow up issue for updating INSTALL.txt. I think these two tasks cover 99.9% of what Nginx users/potential users are looking for. The other .1% is in case 'support for', in this context, wasn't intended to mean 'that Drupal works on'.

jhodgdon’s picture

Project: Drupal core » Documentation
Version: 8.x-dev »
Component: other » Correction/Clarification

I don't think that INSTALL.txt needs to be updated -- it currently says:

Drupal requires:

- A web server. Apache (version 2.0 or greater) is recommended.

And then it says to check the system requirements page for more information. That is probably good enough... we also don't mention IIS in install.txt (although it's on the Requirements page). If you do think we need to patch INSTALL.txt, then please do file a separate issue (Drupal Core / component = documentation) when you're ready.

So it looks like this is now a purely on-line documentation issue, since we don't apparently need to add anything to the core source to support nginx, from what I'm seeing above... So, I'm moving this issue to the Documentation queue so you can continue to collaborate on this. Thanks!

mitchell’s picture

Status: Active » Fixed
Issue tags: -Needs issue summary update, -nginx

Marking as fixed since Nginx is now included in the webserver docs.

There are still a lot of implied or hinted improvements. Here's what I see:

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mpark’s picture

Hello,
would someone help me with install plain vps server for the fastest drupal (multisite)? (of course, nginx, php-ftp, microcache?)

Your effort can pay, of course. We can also arrange custom through freelancer.com.

Mark

batigolix’s picture

You are more likely to find support through the support channels listed at http://drupal.org/support

batigolix’s picture

Issue summary: View changes

Referencing the comment instead of the whole thread.