【问题标题】:How can I force autoindex and ignore index.html files如何强制自动索引并忽略 index.html 文件
【发布时间】:2015-03-25 19:27:56
【问题描述】:

当 nginx 服务一个带有自动索引的目录时,它会列出文件,但是当 index.html 存在时,浏览器会加载该文件。我希望它忽略它。

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

【问题讨论】:

  • 你可以在location中使用index nonexistent-file;

标签: nginx mod-autoindex


【解决方案1】:

输入:index main.html main.htm; 而不是 index index.htm index.html;

【讨论】:

    【解决方案2】:

    这是不可能的。您应该移动其他目录中的其他文件并在 index.html 中创建一个 iframe。

    类似的东西:

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

    希望对你有用。

    【讨论】:

      【解决方案3】:

      这对我有用:

      server {
       listen 80;
       listen [::]:80;
      
       server_name localhost;
      
       autoindex on;
       index =404;
       
       location / {
         root /path_to_www_dir;
       }
      }
      

      【讨论】:

        猜你喜欢
        • 2013-05-26
        • 2019-01-09
        • 2010-10-11
        • 1970-01-01
        • 2015-02-11
        • 2016-04-18
        • 2016-03-10
        • 2021-08-06
        • 1970-01-01
        相关资源
        最近更新 更多