More subdomain mapping (dynamic 'root'?)

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

The URL structure is something like: http://.admin.domain.com/

Where would letters, numbers and underscores , and is a domain name
(e.g. http://cnn.admin.domain.com/www.cnnminiblog.com)

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 *.admin.domain.com;

if ($host ~ ().admin.domain.com) {
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: