NginX VirtualDocumentRoot configuration

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

There is an excellent article on the Drubuntu group about setting up Apache for use in a local development environment. The best thing about it is the clever use of Apache's VirtualDocumentRoot parameter which allows you to set up an infinite number of sites, using just one Apache Virtual host, greatly reducing the time involved with setting up yet another local development site as part of you local multisite development environment. I can simply create a new directory, a symlink and a local hosts entry and I'm up and running with a new site.

eg.
asite.6, anothersite.6, mysite.6 (for all my drupal 6 sites, running in 1 drupal 6 multisite installation)
asite.7, anothersite.7, mysite.7 (for all my drupal 7 sites, running in 1 drupal 7 multisite installation)

So.. Now I finally got round to getting NginX set up on my local Ubuntu development setup (I have been using it in staging and production for a couple of years), but can't see how to mimic such a setup as the way I had Apache configured...

Any ideas?

Comments

Have you checked out

brianmercer's picture

Have you checked out omega8cc's config for aegir at http://groups.drupal.org/node/26363?

I use a similar setup for my dev server. I'm not using aegir and I'm not familiar with their directory structure, but I use a modified Justin Hileman (http://justinhileman.info/articles/a-more-secure-drupal-multisite-install) setup but with another layer of symlinks which lets me change things easier.

@mrfelton

omega8cc's picture

To follow brianmercer, here is simple how-to for all interested in using catch-all nginx configuration, also for Drupal 7.x.

BTW: Aegir doesn't support 7.x as platforms yet/

  • use something like root /var/www/$host/; to enable catch-all nginx config
  • install your multisite instances in:

mkdir -p /var/www/6
mkdir -p /var/www/7
  • create symlinks

ln -s /var/www/6 /var/www/asite.6
ln -s /var/www/6 /var/www/anothersite.6
ln -s /var/www/6 /var/www/mysite.6
ln -s /var/www/7 /var/www/asite.7
ln -s /var/www/7 /var/www/anothersite.7
ln -s /var/www/7 /var/www/mysite.7
  • use standard Drupal multisite setup in sites/domain

Done. To add new site, you don't need to reload/restart nginx. Just create new symlink and new (multi)site dir.

~Grace -- Drupal on Steroids -- http://omega8.cc

Yes, that does work, and is

mrfelton's picture

Yes, that does work, and is what I'm doing. However, what about the Imagecache directory which you need to specify the path to in the nginx conf:

    # imagecache needs to have php read any files that it's planning to manipulate
    location ^~ /sites/example.com/files/imagecache/ {
       index  index.php index.html;
       # assume a clean URL is requested, and rewrite to index.php
        if (!-e $request_filename) {
            rewrite  ^/(.*)$  /index.php?q=$1  last;
            break;
        }
    }

This has the sites hostname hardcoded, so I have to have this entry duplicated for each imagecache directory? Or, perhaps I could alter it to use $host, or some different regex... Got a snippet?!

--
Tom
www.systemseed.com - drupal development. drupal training. drupal support.

@mrfelton

omega8cc's picture

You don't need that /sites/example.com part.
Use just /files/imagecache/ for catch-all.

Omega8cc's updated config

brianmercer's picture

Omega8cc's updated config has:

    location ^~ /blog/files/imagecache/ {
        access_log         off;
        expires            30d;
        try_files $uri @drupal;  #imagecache support
    }

though the "/blog" part looks like a copy/paste error.

I use roughly the same:

    # imagecache needs to process the 404 for missing images so it can create them
    location ^~ /files/imagecache/ {
        access_log        off;
        expires           30d;
        error_page 404 @drupal;
    }

I can't think of any difference between using try_files or error_page. They seem equivalent. Using an if is not preferred.

@brianmercer

omega8cc's picture

Thanks, that /blog/ was a copy/paste error, now fixed there.

perfect - thanks!

mrfelton's picture

perfect - thanks!

--
Tom
www.systemseed.com - drupal development. drupal training. drupal support.

A better way of doing this...

halcyonCorsair's picture

A better way of doing this when using separate code bases...

server {
  listen :80;

  server_name ~^(.+).domain.com$;

  if ($host ~
"^(.+).domain.com$") {
    set $site $1;
  }

  root /var/www/$site;
  access_log /var/log/nginx/autohost.access.log combined;
  error_log /var/log/nginx/autohost.error.log;

  #more stuff
}

Nginx

Group organizers

Group notifications

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