Skip to content

map directive to switch the root for matching subdomains

server {
    server_name mysite.tld ~^.+.mysite.tld$;

    map $host $files {
        default            common;
        mysite.tld         common;
        www.mysite.tld     common;
        admin.mysite.tld   admin;
        system.mysite.tld  system;
        *.mysite.tld       users;
    }
    root /var/www/mysite/$files;
}