1

I want to host a multi-tenant website where tenants can select a siteCode/subdomain, and as long as it's unique, I will create a folder for them and dump static files in there. I then want Nginx to serve the files from the correct folder based on the subdomain. e.g...

acme.domain.com -> serves everything from /acme folder
supermonkey.domain.com -> serves everything from /supermonkey folder
john.domain.com/stuff/stuff-list.html -> serves stuff-list.html from /john/stuff folder

While "domain.com" will be set and initialized by me, I do not want to have to change any config when I add more subdomains (perhaps thousands of them). Just assume I will handle creating the folders and all their contents just fine via an automated process.

Can someone tell me if Nginx can do this first of all, and, if so, what the config would look like?

Tim Hardy
  • 1,654
  • 1
  • 17
  • 36

1 Answers1

0

Try serving the sub domain using regex & refer creating sub domain using nginx

Config example to serve subdomain:

 server {
        server_name   ~^(www\.)?(?<domain>.+)$;

        location / {
            root   /sites/$domain;
        }
    }

or refer stack question answer by Gabriel Hautclocq

Neha Tawar
  • 687
  • 7
  • 23