How can I force autoindex and ignore index.html files

4.2k Views Asked by At

When nginx serves a directory with autoindex, it will list files, but when index.html exists, the browser will load that file. I want it to ignore it.

server {
    listen      80;
    server_name herbert;

    location / {
        root /srv/www;
        index index.htm index.html;
        add_header Cache-Control no-cache;
        expires 300s;
    }

    location /site-dumps/ {

        root /srv/www/;
        autoindex on;
    }
}
3

There are 3 best solutions below

0
Zakwan On

Put: index main.html main.htm; instead of index index.htm index.html;

0
Sandra On

It's not possible. You should move other files in other directory and create an iframe in index.html.

Something like that:

index.html

<iframe src="/site-dumps_files"></iframe>

nginx.cnf

server {
      listen      80;
      server_name herbert;

      location / {
        root /srv/www;
        index index.htm index.html;
        add_header Cache-Control no-cache;
        expires 300s;
      }

      location /site-dumps/ {
        root /srv/www/;
      }

      location /site-dumps_files/ {
        root /srv/www/;
        autoindex on;
      }
}

I hope it useful for you.

0
guest On

this worked for me:

server {
 listen 80;
 listen [::]:80;

 server_name localhost;

 autoindex on;
 index =404;
 
 location / {
   root /path_to_www_dir;
 }
}