Arbitrarily slicing $server_name into subdomains?
Igor Clark
lists at ruby-forum.com
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:
url: http://client.myserver.net/
root: /var/www/docs/myserver.net/client/public
url: http://project.client.myserver.net/
root: /var/www/docs/myserver.net/client/project/public
url: http://sub.project.client.myserver.net/
root: /var/www/docs/myserver.net/client/project/sub/public
(etc.)
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/myserver.net/$my_host/public
which gives me project.client.myserver.net ->
.../myserver.net/client/project/... - 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.
Thanks,
Igor Clark
--
Posted via http://www.ruby-forum.com/.
More information about the nginx
mailing list