is it possible to set locations for subdomains based on subfolders of the
$server_name ?
location matching sub1.domain.com {
serving from /var/www/$server_name/sub1
}
“location” doesn’t match the hostname used. You could use a “map” to
enumerate the hostnames you consider valid, with a default value for
anything else; and use that in “root”.
Currently, I am using a server for each subdomain, but when the number of
subdomains increases, maintaining numerous servers becomes messy.
If every valid hostname is handled equivalently, you could get away
with it being all in one server block.
But you may want to look into “include”, or using an external-to-nginx
template system to turn your starting system into an nginx.conf with
multiple server blocks, if different hostnames are handled differently.