Nginx fancy-index 页眉和页脚从不加载

Nginx fancy-index header and footer never load

我正在创建一个 Nginx 文件服务器,我正在尝试启用 fancy-index 模块以获得自定义页眉和页脚,但我无法让它工作,header/footer 从来没有加载。 (请求甚至没有从浏览器完成)。

目前,我已遵循本教程:https://neilmenon.com/blog/install-nginx-fancyindex

我当前的网站配置是

server {
        listen  80;

        server_name myname;

        autoindex on;
        autoindex_exact_size    off;    
        autoindex_localtime     on;     
        location / {                    
                root /var/www/html
                fancyindex on;
                fancyindex_exact_size off;
                fancyindex_footer /fancy-index/footer.html;
                fancyindex_header /fancy-index/header.html;
                fancyindex_css_href /fancy-index/style.css;
                fancyindex_time_format "%B %e, %Y";
        }
}

我还在文件的第一行nginx.conf中加载了模块

load_module /usr/share/nginx/modules/ngx_http_fancyindex_module.so;

我还要澄清一下,我是 nginx 的新手,所以如果这是我应该注意的常见问题,我深表歉意。

在此先致谢,如有任何帮助,我们将不胜感激

我无法找到使用花式索引的解决方案,但是,我通过使用花式索引所基于的模块 ngx_http_addition_module 找到了解决方法。

这个模块在这里:https://nginx.org/en/docs/http/ngx_http_addition_module.html

基本上,配置如下:

 location / {                    
                root /var/www/html

                addition_types text/html;                  # Replace this with watever mime type this server is responding
                add_before_body /fancy-index/header.html;  # Replace the fancyindex_header 
                add_after_body /fancy-index/footer.html;   # Replace the fancyindex_footer 
        }

您无法从这些指令 link 样式表或更改时间格式,但没有什么可以阻止从 header 加载样式表并在其中添加脚本时间。

我遇到了同样的问题。问题是您启用了自动索引。

要解决此问题,您需要注释引用 autoindex 的行