Here is a simple way to do it.. not how you have it laid out but its using the whole hostname as a directory.. I will look deeper into if nginx can do what you want. I know it can do this
server {
listen 80;
server_name _;
location / {
root /tmp/$host;
index index.html index.htm;
}
}
That will serve up content if you hit http://host1.domain.com in /tmp/host1.domain.com/index.html
EDIT
Here is what you want to do
server {
listen 80;
server_name _;
if ($host ~ (.*)\.(.*)\.domain.com) {
set $myroot /tmp/$1/mas/$2;
}
location / {
root $myroot;
index index.html index.htm;
}
}