Hostname in Root directive

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

location /static {
ie; root /www/$hostname/static;

}

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

http://nginx.org/en/docs/http/ngx_http_core_module.html#variables

for example);

and do you want to accept whatever that variable happens to hold, or do
you want to use something like a map (http://nginx.org/r/map) to set it
to a default value if it doesn’t have a “safe” value, where you define
“safe”?

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

f

Francis D. [email protected]