With a modern pcre library version and nginx, instead of
location ~ ^/([a-zA-Z0-9_]+)/ {
set $username $1;
you can use named captures location ~ ^/(?<username>[a-zA-Z0-9_]+)/ {