With nginx is there a method to setup mass dynamic virtual hosts similar to the way apache2 can be configured? I'm setting up an saas application each user will have their own subdomain and i'd like to use nginx over apache2.
Thanks
Code below should be how to configure
map $http_host $subdir {
hostnames;
default "default";
.foo.bar.com "foo";
.baz.bar.com "baz";
}
server {
root /path/to/$subdir;
}
Best Answer
Yes, setting up virtual hosts is definitely possible, please check Nginx documentation on server configuration directive and default config samples. The easiest way is to put
server
config sections in separate files under/etc/nginx/conf.d
and to include them by a pattern, likeinclude /etc/nginx/conf.d/*.conf;
in the main nginx config file.