Forum: NGINX nginx not using root from location

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
De7b680154f831d87d8ea48743852f14?d=identicon&s=25 reaper (Guest)
on 2016-07-12 16:48
(Received via mailing list)
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:
https://forum.nginx.org/read.php?2,268258,268258#msg-268258
0fb3f929ae7fa773b9c976c1d9b066ac?d=identicon&s=25 Shivam Nanda (Guest)
on 2016-07-12 18:47
(Received via mailing list)
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
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2016-07-12 19:30
(Received via mailing list)
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 Daly        francis@daoine.org
De7b680154f831d87d8ea48743852f14?d=identicon&s=25 reaper (Guest)
on 2016-07-12 21:47
(Received via mailing list)
Yes! That was it. Thank you.

Strange that nginx -t didn't say anything wrong with config :(

Posted at Nginx Forum:
https://forum.nginx.org/read.php?2,268258,268261#msg-268261
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2016-07-12 22:11
(Received via mailing list)
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 Daly        francis@daoine.org
This topic is locked and can not be replied to.