Arbitrarily slicing $server_name into subdomains?

Igor Clark lists at
Wed Jan 6 22:24:40 MSK 2010

Hi there, hope all are well!

I'd like to match a wildcard DNS name, pointing to an nginx virtual
host, such that an arbitrary level of subdomains maps to an arbitrary
level of directories, in a manner I specify.

For example:

    root: /var/www/docs/

    root: /var/www/docs/

    root: /var/www/docs/


It's straightforward to do this for a fixed level of
subdomains/directories using a server_name regex, for example:

        server_name    ~^(.*)\.(.*)\.myserver\.net$;
        set    $my_host $2/$1;
        root    /var/www/docs/$my_host/public

which gives me ->
.../ - but the whole point of using
wildcards like this is that I don't want to keep adding new configs.

Is it possible to do this, perhaps using the perl config module? Or
maybe just a smarter regex?

Very grateful for any suggestions.

Igor Clark
Posted via

More information about the nginx mailing list