Nginx : autoindex not working

configurationnginxweb-server

Hello all I'm following a guide https://www.youtube.com/watch?v=7QXnk8emzOU and exactly did everything same and I've checked other similar problems such as nginx autoindex doesn't work and Issues with nginx autoindex .

Configuration file of 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
        }
}

The html files are located at /test/a, one is /test/a/index.htm, other is /test/a/outdex.htm. I see the content of index.htm when I connect to IP of server.

I have recursively changed permissions of all the content for avoiding permission issues earlier as :

chmod 777 -R /test

Best Answer

After some error and trial I've reached the solution. My problem actually was trivial. The line which starts with index defines files that are going to be used as index, since I have just put there a single file, not a directory, it was the only thing I got, after making changing index as below, I got what I was expecting.

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
        }
}

Sources :

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

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