How to serve subdomain from subfolder of the domain root?

etrader nginx-forum at
Sat Sep 14 05:42:49 UTC 2013

In a server as

server {
server_name *
root  /var/www/$server_name;

is it possible to set locations for subdomains based on subfolders of the
$server_name ?

location matching {
serving from /var/www/$server_name/sub1

Currently, I am using a server for each subdomain, but when the number of
subdomains increases, maintaining numerous servers becomes messy.

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

More information about the nginx mailing list