server {
listen 80;
server_name example.com *.example.com;
root /var/www/example.com/$subdomain;
set $subdomain "";
if ($host ~* ^([a-z0-9-\.]+)\.example.com$) {
set $subdomain $1;
}
if ($host ~* ^www.example.com$) {
set $subdomain "";
}
....
}
Адрес URL Путь на сервере
http://example.com/ /var/www/example.com/
http://www.example.com/ /var/www/example.com/
http://vasya.example.com/ /var/www/example.com/vasya/
http://vasya.ivanov.example.com/ /var/www/example.com/vasya.ivanov/