使用 autoindex 时 Nginx 错误 404

Nginx error 404 when using autoindex

我对 nginx 完全陌生。我已经在 windows 台电脑上安装了 nginx。

我想要做的是在 localhost:8082/list 上为 D:\ 中的文件列表提供服务器。

如果我使用以下配置:

server {
    listen       8082;

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

我可以在 localhost:8082 上正确看到我想要的内容。但是如果我把它改成:

server {
    listen       8082;

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

页面 localhost:8082/list 出现 404 错误。

你需要的是alias而不是root

server {
    listen       8082;

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

Nginx -- static file serving confusion with root & alias