nginx:目录列表中的长文件名

eva*_*ine 9 openbsd nginx

使用 nginx/1.4.1 和 OpenBSD 5.4,64 位:

在此处输入图片说明

在使用目录列表时,我们如何设置 nginx 以显示完整的文件名(或至少从文件名中显示更多的默认文件名)?

谷歌搜索只给了我这个:

http://forum.nginx.org/read.php?2,124400,167420#msg-167420
January 18, 2011 08:36PM
fagtron
I looked all over the net and wasn't able to find this answer anyway, so I looked into the nginx source files and it's very easy.

Simply modify the file located at [b]src/http/modules/ngx_http_autoindex_module.c[/b] and then compile.

Change these lines:

[b]#define NGX_HTTP_AUTOINDEX_PREALLOCATE 50

#define NGX_HTTP_AUTOINDEX_NAME_LEN 50[/b]

to whatever you want, such as:

[b]#define NGX_HTTP_AUTOINDEX_PREALLOCATE 100

#define NGX_HTTP_AUTOINDEX_NAME_LEN 100[/b]

And then compile and restart nginx. That's it !!!
Run Code Online (Sandbox Code Playgroud)

问题:有没有其他方法可以重新编译它?

小智 6

您可以尝试使用带有fancyindex_name_length 参数的fancyindex 模块来配置文件名长度。

  • 这应该是公认的答案。请注意,nginx 页面上没有提到 `fancyindex_name_length`,而是在模块的 github 页面上。请注意,此模块包含在 `nginx-extras` 包中。 (2认同)

ssh*_*ksh 5

根据ngx_http_autoindex_module文档,自动索引页面的列宽配置不可用。从源代码编译将是进行此更改的唯一方法。

一种替代方法是使用脚本语言(例如phpruby、 或python)为您执行目录列表。

好处包括:

  • 通过 CSS、JavaScript 等完全可定制
  • 精细控制文件列表

注意事项:

  • 需要CGI例如php-fpmpassenger
  • 需要更多配置