# Hostname in Root directive

**URL:** <https://www.ruby-forum.com/t/hostname-in-root-directive/235851>\
**Category:** NGINX\
**Created:** [July 19, 2013, 4:56pm UTC](https://www.ruby-forum.com/t/hostname-in-root-directive/235851 "2013-07-19T16:56:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [July 19, 2013, 4:56pm UTC](https://www.ruby-forum.com/t/hostname-in-root-directive/235851/1 "2013-07-19T16:56:26Z")

</div>

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;

}

---

<div class="post-metadata">

**Author:** ![David\_S\_StyleFlare](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@David\_S\_StyleFlare](https://www.ruby-forum.com/u/David_S_StyleFlare)\
**Post date:** [July 19, 2013, 5:42pm UTC](https://www.ruby-forum.com/t/hostname-in-root-directive/235851/2 "2013-07-19T17:42:37Z")

</div>

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

[Module ngx\_http\_core\_module](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 ([Module ngx\_http\_map\_module](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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
