Forum: NGINX Root inside Location Block? Pitfalls says NO, Beginner’s Guide says YES

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
chrisrob (Guest)
on 2013-09-19 12:58
(Received via mailing list)
Practically the first two pages I read when starting with nginx were:

which says "putting Root inside Location Block is BAD" - don't do it.


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?


Posted at Nginx Forum:,242986,242986#msg-242986
Maxim Dounin (Guest)
on 2013-09-19 13:28
(Received via mailing list)

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 Dounin
chrisrob (Guest)
on 2013-09-19 14:20
(Received via mailing list)
Thanks Maxim,

That's pretty obvious I suppose - providing that a root at Server
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,
that just jumped out at me. I'd better make sure I read all the docs
posting here again - but I still think "Pitfalls" could be more
moan, moan...


Posted at Nginx Forum:,242986,242990#msg-242990
This topic is locked and can not be replied to.