Hostname in Root directive.

Francis Daly francis at
Fri Jul 19 15:41:48 UTC 2013

On Fri, Jul 19, 2013 at 10:55:57AM -0400, David | StyleFlare wrote:

Hi there,

> I know this may not be safe, but how can I set the hostname in the root 
> directive

> ie; root /www/$hostname/static;

By using a variable, just like you've done there.

Two things you need to decide:

what exact variable do you want to use? (There's a list of core-module
pre-defined variables at

for example);

and do you want to accept whatever that variable happens to hold, or do
you want to use something like a map ( to set it
to a default value if it doesn't have a "safe" value, where you define

"hostname" might be $http_host, or $host, or $server_name (with increasing
amounts of trust), or maybe something else entirely.

Francis Daly        francis at

More information about the nginx mailing list