
Nginx 做文件服务器时,只要打开了autoindex就可以作为一个简易的文件服务器。然而Nginx 默认的配置下,长文件名会以省略号显示。
这么常见的问题,我去搜了一圈都没发现比较简单的方法,才有了本文
Stackoverflow 上给有个问题给出了几种解决方案

- 重新编译 Nginx ,改变 NGX_HTTP_AUTOINDEX_NAME_LEN
- 使用 fancyIndex 模块
两个都要重新编译Nginx,那就很麻烦了,不想动弹。
很久以前我知道nginx 要加载模块 还是要重新编译 Nginx 的,不过我记得几年前 Nginx 退出了 “激动人心的” (早就该有的)动态模块特性,于是乎去搜了下,fancyIndex官网上并没提自己可以用动态库方式加载。还好我有 Ubuntu, apt search fancyindex 找到了,那就简单了
- 装fancyindex模块
sudo apt install libnginx-mod-http-fancy index
- 改配置 (知乎有nginx configuration 高亮,好评)
location / { charset utf-8; root /directory/to/index; fancyindex on; fancyindex_name_length 500; }
- reload Nginx
sudo nginx -s reload
Enjoy