Regular expressions in server_name with Nginx vhost

Solution 1:

That expression will never match, since $ is in the middle of the string. Try:

server_name ~^(?<site_id>.+)\.dev\.example\.com$;