Contents

Configuration project

Caution: This project is NOT a drop-in configuration setup. It's designed to leverage the best of what Nginx and Drupal have to offer. The rest of this page details a more common and very easy to understand approach.

Guide

There seems to be a lot of controversy as to the best way to put Nginx in front of Drupal without passing to an Apache server. Rather than explain the reasons all of these configs are wrong, I'd rather explain a better way. (Followed by bad)

Little About The Others

There's really no need to tell Nginx to listen to only a single interface. By default Nginx will listen to all interfaces. If you're reading this, then there's probably not much reason for you to have this line.

For the love of god, stop doing this. Not YOU. Everyone out there that does this and spreads it. The root and index directives do not belong here. Check out the Pitfalls page for an explanation of why.

This isn't 'wrong' per say. You will get better performance and more security by binding to a socket though. You're no longer exposing a point of attack. With ports you're limited to the number of ports available on the system and you can't dynamically allocate them. In the case of sockets, you can control, allocate, and utilize them much easier.

You know how I complained about "location = / { root /path/to/drupal; }" above? Why am I bringing it up again? If you set your root properly then instead of "/path/to/drupal" you could just use "$document_root". What makes it amazing is that you then have one less line that needs to change whenever you change things. The root is just setup.

This is minor at best. A full path is not needed if your config is inside of your nginx config directory. The better option here is to just use "include fastcgi.conf;" Better would be to leave the .conf off of a file that's not read dynamically.

Notes

Drupal in a subdirectory

If you're running Drupal in a subdirectory, you will need to tweak the rewrite directive a bit. The example above would take a URL like example.com/drupal/node/123 and ask Drupal for example.com/index.php?q=drupal/node/123 , which obviously won't work for subdirectory hosting. This alternative rewrite string handles Drupal in one level of subdirectory (ie /drupal/node/123 , but not /directory/drupal/node/123 ). For more exotic configurations, simply tweak the regular expression used for the rewrite directive.

In case it wasn't obvious, if you are using imagecache with a non-standard upload directory (site option or media mover) you will need to update the regex above to the proper directory. Such as, if you move the upload directory to /uploads on your site, you will need to change the configuration as follows:

Even after reading IfIsEvil, there is a corner case for drupal sites that migrated from other software (forums, mediawiki, etc.). These site migrations use url aliases or menu mappings via modules to handle old .php files. This breaks the .php location provided above, so using HTTP error code 418 and a few conditionals, we pass on lookups or 404's to Drupal.