Isso é melhor realizado usando três servidores:
# www.domain.com, actually serves content
server {
server_name www.domain.com;
root /doc/root;
# locations, etc
}
# redirect domain.com -> www.domain.com
server {
server_name domain.com;
rewrite ^ http://www.domain.com$request_uri? permanent;
}
# handle anything.domain.com that wasn't handled by the above servers
server {
# ~ means regex server name
# 0.8.25+
#server_name ~(?<city>.*)\.domain\.com$;
# < 0.8.25
server_name ~(.*)\.domain\.com$;
set $city $1;
location = / { rewrite ^ http://www.domain.com/$city/prelaunch; }
location = /landing { rewrite ^ http://www.domain.com/$city/prelaunch; }
# should there be a /$city before $request_uri?
location / { rewrite ^ http://www.domain.com$request_uri?; }
}