A different way would to use Lua and an alias table, for a dynamic site I use this to allow a site multiple aliases all directing to the same root, its a simple array with 2 lines for each main site, 1 as server_name and line 2 endless aliases. Its fast and no need to edit nginx.conf just edit a plain ascii file.