0

UPDATED nginx.conf FILE AND ANYTHING ELSE TO THE LATEST STATE
BUT STILL GETTING 404 ERRORS :-(

So i was trying to setup directory listing on my server with nginx, i followed the instructions step-by-step but nothing worked out -- always popping either 403 or 404 errors while permissions are all set to 755...

When i enable autoindex on the root location it worked fine, but when i put it on the "dl/" location, it either shows a 404 when requesting /dl or 403 when requesting /dl/

After i followed @Bryce Larson's steps...403 is gone now only 404 is there...which is still not okay...


# pwd
/root/Downloads/dl

# ls -lha
total 12K drwxr-xr-x 2 nginx root 4.0K Nov 25 20:01 . drwxr-xr-x 4 root root 4.0K Nov 26 09:11 .. -rwxr-xr-x 1 nginx root 26 Nov 25 20:01 blah.txt


Here's the nginx.conf:
https://0bin.net/paste/he2oIb2OFou4G9Fd#v5qt5M7scM8jlSRkl9B+GepP+PoInAHrfZrJNJ7Ch9U I'm gonna use 0bin for long code/config etc to save time&effort, plus it's got syntax coloring ;-)


And yeah i've restarted nginx a hundred times just to make sure it takes the new config...so what's wrong now?

Otherwise, how would you configure the nginx server for this purpose? -- your own nginx.conf files are welcomed plz paste it here: https://0bin.net

1
  • And sometimes 403 as well...really no clue what's wrong... – Samm Nov 26 '16 at 2:48
1

I eventually found the solution myself X-(
So to specify the location with root, ur gonna have to specify the parent directory instead of the directory that ur planning to serve (which is pretty obvious now that i think of it -- it's the god damn root!).
So as in my example i should specify /root/Downloads with the root parameter, then the server is gonna try to find a dir named dl within it.
I did recall trying this way but the permission issues as mentioned by @Bryce Larson could be the reason why it didn't succeed.

Here's the final nginx.conf in case people are interested.


Conclusion:

The correct way to setup directory listing in nginx is to
A. specify the parent directory of the directory that ur trying to serve.
B. make sure the permissions from / all the way to the directory that ur trying to serve is set executable, i.e chmod +X -R .

0

If you're serving it from root's home directory make sure the directories have execute permission for every directory from root (/) up to the directory you are serving. By default, root usually has 700 permissions on it's home directory. Execute permissions on directories are required to 'cd' to that directory, which nginx can't do if the execute permission isn't allowed on the directories for the user nginx runs under.

also:

chmod +X -R .

is quite useful as it only changes directory permissions and not files, see: https://www.franzoni.eu/chmod-and-the-capital-x/

3
  • I tried that by chmod -R +x /root and now it's just saying 404 :-( – Samm Nov 26 '16 at 4:20
  • Are you trying to make /root/Downloads/dl served up, or /root/Downloads/pub as shown in your pwd? – Bryce Larson Nov 26 '16 at 18:10
  • Ahh...i changed the name to dl.. – Samm Nov 27 '16 at 2:12
0

For anyone stumbling across this thread because they also get a 404 (like me), but couldn't resolve it with the solution above:

It appears that the autoindex on; doesn't work when the specified root directory contains spaces, even if they are escaped correctly.

In my test the following did NOT work:

server {
    listen 80;
    servername downloads.myserver.com;

    location / {
        # notice escaped space character here:
        root /mnt/mydrive/test\ test/;
        autoindex on;
    }
}

But this did work:

server {
    listen 80;
    servername downloads.myserver.com;

    location / {
        # notice no escaped space character here:
        root /mnt/mydrive/testtest/;
        autoindex on;
    }
}

If anyone knows why nginx doesn't like spaces in the root directory, I'd be happy to learn why.

1
  • Did you try root '/mnt/mydrive/test test/';? – Paul Jun 26 at 3:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.