Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force autoindex and ignore index.html files

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;
    }
}
like image 264
caduceus Avatar asked Jan 27 '15 08:01

caduceus


People also ask

What is autoIndex in nginx?

Nginx autoindex directives autoindex_exact_size; - This directive specifies whether Nginx should display the exact file sizes of the output in the directory index or simply round to the nearest KB, MB, or GB. This directive has two options: on or off .

What is in index html?

Default Homepage The index. html page is the most common name used for the default page shown on a website if no other page is specified when a visitor requests the site. In other words, index. html is the name used for the homepage of the website.

What is autoIndex?

autoIndex = true; means to respond with /path/index. html when /path/ is requested. It's a part of ecstatic package api. Follow this answer to receive notifications.


1 Answers

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.

like image 169
Sandra Avatar answered Sep 22 '22 21:09

Sandra