# Root inside Location Block? Pitfalls says NO, Beginner’s Guide says YES

**URL:** <https://www.ruby-forum.com/t/root-inside-location-block-pitfalls-says-no-beginner-s-guide-says-yes/246259>\
**Category:** NGINX\
**Created:** [September 19, 2013, 12:58pm UTC](https://www.ruby-forum.com/t/root-inside-location-block-pitfalls-says-no-beginner-s-guide-says-yes/246259 "2013-09-19T12:58:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [September 19, 2013, 12:58pm UTC](https://www.ruby-forum.com/t/root-inside-location-block-pitfalls-says-no-beginner-s-guide-says-yes/246259/1 "2013-09-19T12:58:31Z")

</div>

Practically the first two pages I read when starting with nginx were:

> **[Pitfalls and Common Mistakes | NGINX](https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/)**
>
> This page outlines some of the NGINX configuration issues that we see frequently and then explains how to resolve them.

which says “putting Root inside Location Block is BAD” - don’t do it.

and

[http://nginx.org/en/docs/beginners\_guide.html](http://nginx.org/en/docs/beginners_guide.html)

which gives this as its example of a config file:

The resulting configuration of the server block should look like this:

server {  
location / {  
root /data/www;  
}  
location /images/ {  
root /data;  
}  
}

So I’m wondering which is right?

Cheers,  
chrisrob

Posted at Nginx Forum:

> **[Root inside Location Block? Pitfalls says NO, Beginner’s Guide says YES](https://forum.nginx.org/read.php?2,242986,242986#msg-242986)**
>
> Practically the first two pages I read when starting with nginx were: http://wiki.nginx.org/Pitfalls which says "putting Root inside Location Block is BAD" - don't do it. and http://nginx.org/en/docs/beginners\_guide.html

---

<div class="post-metadata">

**Author:** ![chrisrob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@chrisrob](https://www.ruby-forum.com/u/chrisrob)\
**Post date:** [September 19, 2013, 1:28pm UTC](https://www.ruby-forum.com/t/root-inside-location-block-pitfalls-says-no-beginner-s-guide-says-yes/246259/2 "2013-09-19T13:28:55Z")

</div>

Hello!

On Thu, Sep 19, 2013 at 06:57:35AM -0400, chrisrob wrote:

> which gives this as its example of a config file:  
> }
> 
> So I’m wondering which is right?

As you can see, the example in begginners guide uses _different_  
roots for locations configured, and hence it’s very different from  
the example provided at Pitfalls wiki page.

Using the “root” directive inside a location block isn’t bad per  
se. It’s bad if you repeat it needlessly instead of using single  
root inside a server{} block.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![chrisrob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@chrisrob](https://www.ruby-forum.com/u/chrisrob)\
**Post date:** [September 19, 2013, 2:20pm UTC](https://www.ruby-forum.com/t/root-inside-location-block-pitfalls-says-no-beginner-s-guide-says-yes/246259/3 "2013-09-19T14:20:56Z")

</div>

Thanks Maxim,

That’s pretty obvious I suppose - providing that a root at Server  
context  
level is always the default in absence of root in Location Block.

I had only been reading the docs for 30 mins, after downloading nginx,  
and  
that just jumped out at me. I’d better make sure I read all the docs  
before  
posting here again - but I still think “Pitfalls” could be more  
specific,  
moan, moan…

Chris

Posted at Nginx Forum:

> **[Re: Root inside Location Block? Pitfalls says NO, Beginner’s Guide says YES](https://forum.nginx.org/read.php?2,242986,242990#msg-242990)**
>
> Practically the first two pages I read when starting with nginx were: http://wiki.nginx.org/Pitfalls which says "putting Root inside Location Block is BAD" - don't do it. and http://nginx.org/en/docs/beginners\_guide.html
