使用自动索引时 Nginx 错误 404

标签 nginx nginx-location

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

我想要做的是服务器 D:\ 中的文件列表在 localhost:8082/list .

如果我使用以下配置:

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

关于使用自动索引时 Nginx 错误 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44801064/

相关文章:

PHP fatal error : Call to undefined function mysql_connect()

azure - HAProxy 中的 Proxy_pass 等效项

Nginx fastcgi_read_timeout 在特定位置

NGINX 没有将调用从 React 应用程序路由到后端应用程序

nginx - proxy_pass 基于 header 而不使用 if 条件

ssl - 具有多个证书的简单 ssl 终止。 Nginx/haproxy 还是其他?

使用 Nginx 和 Docker 的 Angular 4 SEO

docker - webdevops nginx-从网址中删除.php要求

NGINX:主位置 block 覆盖子目录位置?

php - 如何允许 www-data 用户使用 nginx 执行 bash 脚本