I actually forgot to publish this blog post, but since I seem to get a lot of traffic to my post about mass virtual hosting with Apache, I feel like I should probably write this simply for the sake of completeness, even though it's brutally simple.

If you need a place to start with nginx, I am a fan of the H5BP configs.

All the mass virtual hosting magic here happens when we get to an individual site.

1 server {
2     listen 80;
3     server_name *.example.com;
4     root /wwwroot/vhosts/$host;
5 
6     [...]
7 }

That's really all there is to it. You can now create all sorts of crazy directories in your /wwwroot/vhosts/ directory and they'll get served.

1.example.com
1.2.example.com
etc.

Reload nginx. Profit.