Welcome! Log In Create A New Profile

Advanced

Weird 404, only when serving static on “location /”

Posted by ngxxxx 
Weird 404, only when serving static on “location /”
August 10, 2016 02:55PM
Nginx throws 404 when I try to serve files from a root in "location /". But if I put the same path in "location /something/", it works:

~~~~

server {
listen 8080;

server_name localhost;

location / {
root /home/username/Documents/app/static;

--------> // http://localhost:8080/something/file.js // --> Gives me 404
--------> // http://localhost:8080/file.html // --> Gives me 404
--------> // Everything is 404
}

location /something/ {
root /home/username/Documents/app/static;

--------> // http://localhost:8080/something/file.js // --> Works!!!
}
}

~~~~

I'm running a Node server within Nginx, on a different port, but I don't see how that would affect anything.
Re: Weird 404, only when serving static on “location /”
August 10, 2016 04:14PM
location /something/
gets added to the root value.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Weird 404, only when serving static on “location /”
August 10, 2016 04:35PM
From the official documentation: https://nginx.org/en/docs/beginners_guide.html#static

location / {
root /data/www;
}

^^^ My problem: This does not work for me.
Re: Weird 404, only when serving static on “location /”
August 10, 2016 05:20PM
If the data you serve does not live in /data/www then change the root value.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Weird 404, only when serving static on “location /”
August 10, 2016 05:34PM
I made a /data/www folder and put files in it, but it does not work. Nginx V1.10.0 Ubuntu 16.04 x64
Re: Weird 404, only when serving static on “location /”
August 11, 2016 01:56AM
Check the nginx logfiles, or enable debug logging to see exactly what is happening.

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 104
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready