Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx error 404 when using autoindex

I'm completely new to nginx. I've installed nginx on windows pc.

What I want to do is server a list of files in D:\ on localhost:8082/list.

If I use the following conf:

server {
    listen       8082;

    location / {
        root D:/;
        autoindex on;
    }
}

I can correctly see what i want on localhost:8082. But if I change it to:

server {
    listen       8082;

    location /list {
        root D:/;
        autoindex on;
    }
}

The page localhost:8082/list gives a 404 error.

like image 287
imlokesh Avatar asked Jun 28 '17 11:06

imlokesh


1 Answers

What you need is alias instead of root.

server {
    listen       8082;

    location /list {
        alias D:/; ##### use alias, not root
        autoindex on;
    }
}

See Nginx -- static file serving confusion with root & alias

like image 176
Anand Bhat Avatar answered Oct 29 '22 00:10

Anand Bhat