We're making a move over to some Nginx servers from Apache. While we've used Nginx for various sites its been in a mostly basic config. However, one of the 'sites' (multiple actually) we host is a sandbox type of site such that our developers can login to the server create a directory and they have a site up and running. I'm trying to figure out how to replicate this with Nginx but am unable to wrap my head around it thus far. Any help would be appreciated.
Server Directory Setup Example:
/home/[USER]/sandbox/site1
/home/[USER]/sandbox/site2
... etc.
Apache Config:
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
ServerAlias *.*.example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.example\.com$ [NC]
RewriteRule ^(.*)$ /home/%1/sandbox/%2/$1 [L]
<Directory />
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Resulting Domain:
[USER].site1.example.com
[USER].site2.example.com
.... etc.
What would be the equivalent in Nginx to parse the host and correctly route internally to said directory?
Maybe something like this: