More subdomain mapping (dynamic 'root'?)

miradev nginx-forum at
Wed Jul 1 14:23:12 MSD 2009

I want to be able to map submains and urls to determined locations on disk, if they exist.

The URL structure is something like:

Where  would letters, numbers and underscores , and  is a domain name (e.g.

Nginx should check if /var/www/clients//admin//html/ exists and use that as root:

Some horrible pseudo code:

server {
  listen localhost: 80;
  server_name *;

  if ($host ~ (*) {
    set $client = $1;
    if ($url ~ ^([^/]*)) {
      set $project = $1;
      set $myroot = /var/www/clients/$client/admin/$project/html;
      if ( -e $myroot ){
        root $myroot;

If this is not very 'nginxy', I am very open to alternate solutions.

Posted at Nginx Forum:,3586,3586#msg-3586

More information about the nginx mailing list