Nginx:自动索引不起作用

Nginx:自动索引不起作用

大家好,我正在遵循指南https://www.youtube.com/watch?v=7QXnk8emzOU并做了同样的事情,我已经检查了其他类似的问题,例如nginx 自动索引不起作用nginx 自动索引问题

nginx的配置文件:

server {
        listen 80;                      #says to listen on standard port
        server_name _;                  #the default server
        location / {                    #location is the root of the site
                root /test/a/;          #root is located at /test/a/  
                index index.htm;        #index is for autocomplete
                autoindex on;           #this way files will be autoindexed
        }
}

html 文件位于/test/a,一个是/test/a/index.htm,另一个是/test/a/outdex.htm。当我连接到服务器的 IP 时,我看到了 index.htm 的内容。

为了避免出现权限问题,我已递归地更改了所有内容的权限,如下所示:

chmod 777 -R /test

答案1

经过一些错误和尝试,我找到了解决方案。我的问题其实很简单。以 开头的行index定义了将用作索引的文件,因为我只在那里放了一个文件,而不是目录,所以我得到的唯一结果就是它,在按如下所示更改索引后,我得到了我所期望的结果。

server {
        listen 80;                      #says to listen on standard port
        server_name _;                  #the default server
        location / {                    #location is the root of the site
                root /test/a/;          #root is located at /test/a/  
                index test;        #index is for autocomplete
                autoindex on;           #this way files will be autoindexed
        }
}

资料来源:

http://nginx.org/en/docs/http/ngx_http_index_module.html

https://www.youtube.com/watch?v=7QXnk8emzOU

相关内容