仅Nginx目录列表用于子路径

问题描述 投票:0回答:1

我试图使我的子路径仅在Nginx中成为目录列表,但是它返回404。

假设我具有http://file.example.com/test的以下配置:

server {
    listen        80;
    server_name  file.example.com;

    location /test/ {
        root    /var/www/abc/def/;
        autoindex on;
        autoindex_exact_size off;
        autoindex_format html;
        autoindex_localtime on;
    }
}

我未指定/部分,是否是上述问题导致的无效?我错过了什么?

nginx nginx-location nginx-config
1个回答
0
投票

将位置更改为location /test

将所有文件复制到/var/www/abc/def/test文件夹,因为您将位置指令与根指令一起使用。对于您的情况,当Nginx搜索静态文件时,它将使用根路径/var/www/abc/def并附加位置路径/test

或使用别名,如@RichardSmith建议。

© www.soinside.com 2019 - 2024. All rights reserved.