Nginx clean-URLs for Drupal installed in various sub-directories

klausi has already posted a nice, actually working nginx configuration for Drupal on his blog. This configuration is intended for Drupal installations installed on separate (sub)domains. However, recently I came up with the need of having multiple Drupal installations in sub-directories for my development environment. To achieve that I've created the following location directive:

        location ~ ^/([^/]*)/(.*)$ {
                try_files $uri /$1/index.php?q=$2&$args;
        }

That way, you can just add as many Drupal installations as you want in sub-folders, while they are automatically clean-URL enabled. :)

Comments

Running several drupal sites under a same root, is a bad idea IMHO. That's something that made sense in Apache, but which doesn't map to a production setup with nginx.

Instead the easiest way of doing that is using different ports for different sites. That way you only need to change the port and add a server_name directive, possibly also the document root. And you're done: you have a production ready setup.

Also regex based locations are to be avoided whenever possible they're bound to introduce unwanted side effects sooner or later.

As said I'm using it for my development, where this kind of flexibility is useful. Whether its something people want to use on production is another question. Usually you probably won't.

Very informative text, thanks for sharing it!

I love it when people come together and share opinions, great blog, keep it up.

I love it when people come together and share opinions, great blog, keep it up.

I love it when people come together and share opinions, great blog, keep it up.

Add new comment

Filtered HTML

  • To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.
  • Allowed HTML tags: <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.