# Nginx not using root from location

**URL:** <https://www.ruby-forum.com/t/nginx-not-using-root-from-location/244934>\
**Category:** NGINX\
**Created:** [July 12, 2016, 4:48pm UTC](https://www.ruby-forum.com/t/nginx-not-using-root-from-location/244934 "2016-07-12T16:48:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [July 12, 2016, 4:48pm UTC](https://www.ruby-forum.com/t/nginx-not-using-root-from-location/244934/1 "2016-07-12T16:48:17Z")

</div>

Hello. I’m obviously missing something but I’m not quite sure what.

Here’s one of my vhosts.

server {  
listen 80;  
server\_name test.local;

access\_log /var/log/nginx/access.log;

root /data/www/htdocs/web;

location / {  
index index.php;  
}

location /testlocation {  
index index.html  
root /data/www/htdocs/test;  
}  
}

When I try to get index.html from /testlocation I always get 404 with  
message in errorlog that file is missing in /data/www/htdocs/web. Why?

Posted at Nginx Forum:

> **[nginx not using root from location](https://forum.nginx.org/read.php?2,268258,268258#msg-268258)**
>
> Hello. I'm obviously missing something but I'm not quite sure what. Here's one of my vhosts. server { listen 80; server\_name test.local; access\_log /var/log/nginx/access.log; root /data/www/htdocs/web;

---

<div class="post-metadata">

**Author:** ![reaper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@reaper](https://www.ruby-forum.com/u/reaper)\
**Post date:** [July 12, 2016, 6:47pm UTC](https://www.ruby-forum.com/t/nginx-not-using-root-from-location/244934/2 "2016-07-12T18:47:27Z")

</div>

Hi Reaper

please check the following:

1. check the permissions of the folders.
2. define both root directive in the location.

restart the nginx service and share the results.

Thanks

Shivam

---

<div class="post-metadata">

**Author:** ![reaper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@reaper](https://www.ruby-forum.com/u/reaper)\
**Post date:** [July 12, 2016, 7:30pm UTC](https://www.ruby-forum.com/t/nginx-not-using-root-from-location/244934/3 "2016-07-12T19:30:41Z")

</div>

On Tue, Jul 12, 2016 at 10:47:56AM -0400, reaper wrote:

Hi there,

> Hello. I’m obviously missing something but I’m not quite sure what.

You don’t have a “root” directive inside the location.

Your “index” directive as-written has three arguments, although you want  
it to only have one.

> location /testlocation {  
> index index.html  
> root /data/www/htdocs/test;  
> }

Add a semicolon to tell nginx that your “index” directive is complete.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![reaper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@reaper](https://www.ruby-forum.com/u/reaper)\
**Post date:** [July 12, 2016, 9:47pm UTC](https://www.ruby-forum.com/t/nginx-not-using-root-from-location/244934/4 "2016-07-12T21:47:57Z")

</div>

Yes! That was it. Thank you.

Strange that nginx -t didn’t say anything wrong with config ☹

Posted at Nginx Forum:

> **[Re: nginx not using root from location](https://forum.nginx.org/read.php?2,268258,268261#msg-268261)**
>
> Hello. I'm obviously missing something but I'm not quite sure what. Here's one of my vhosts. server { listen 80; server\_name test.local; access\_log /var/log/nginx/access.log; root /data/www/htdocs/web;

---

<div class="post-metadata">

**Author:** ![reaper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f04885/32.png) [@reaper](https://www.ruby-forum.com/u/reaper)\
**Post date:** [July 12, 2016, 10:11pm UTC](https://www.ruby-forum.com/t/nginx-not-using-root-from-location/244934/5 "2016-07-12T22:11:19Z")

</div>

On Tue, Jul 12, 2016 at 03:47:23PM -0400, reaper wrote:

Hi there,

> Yes! That was it. Thank you.

Good stuff.

> Strange that nginx -t didn’t say anything wrong with config ☹

There’s nothing wrong with the config. It is syntactically correct.

When you request /testlocation/, nginx will look for the  
file /data/www/htdocs/web/testlocation/index.html, then the  
file /data/www/htdocs/web/testlocation/root, then the file  
/data/www/htdocs/web/data/www/htdocs/test, and then fail 404, which is  
exactly what you told it to do.

The fact that that is not what you _wanted_ to tell nginx to do, is not  
something that nginx can reliably guess. So it doesn’t try.

Cheers,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
