> map $arg_needle $needle_host { > default '127.0.0.1:3000'; > ~^ $arg_needle.somehost.com; > } Or a bit more efficient, without regexes: map $arg_needle $needle_host { default $arg_needle.somehost.com '' '127.0.0.1:3000'; }