Store part of subdomain in a variable to use as root

martinc6 nginx-forum at
Thu Aug 6 10:24:53 MSD 2009

I need to store part of a subdomain in a variable in order to use it as my root and I can't seem to get it to work.

The URLs would be formed like:

And I need root to be /home/martin/

The underscore ("_") and stuff afterwards is optional. I'll also need to have its root as /home/martin/

Note that the name ("martin") and home folder will vary.

This is what I've got so far:

server {
        listen   80;
        server_name ~^(.+)_*\.dev\.testsite\.com$;
        set $myroot $1;
        root /home/$myroot/$host;

Thanks in advance!

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

More information about the nginx mailing list