I'm feeling lucky: http://wiki.codemongers.com/NginxHttpRewriteModule The page has an example that does exactly what I needed: $host_without_www. And at the same time I understand better how the variables work, how rewriting works and how to create new variables.