POSTS
nginx+fancyindex模块实现浏览目录功能
- nginx打开目录浏览功能可以用 autoindex,在nginx.conf文件中加入:
location / {
autoindex on;
autoindex_localtime on; #之类的参数写这里
}
但上面方式实现浏览的目录很不美观,这篇将介绍另一种方式,加入fancyindex模块。
安装nginx、加入fancyindex模块。
#下载nginx
wget http://nginx.org/download/nginx-1.14.0.tar.gz
#下载fancyindex模块
wget -O fancyindex.zip https://github.com/aperezdc/ngx-fancyindex/archive/v0.4.3.zip
#下载主题
wget -O fancytheme.zip https://github.com/Naereen/Nginx-Fancyindex-Theme/archive/master.zip
#解压
tar -zxvf nginx-1.14.0.tar.gz
unzip fancyindex.zip
unzip fancytheme.zip
- 编译nginx并加入fancyindex模块
cd nginx-1.14.0
./configure --add-module=../ngx-fancyindex-0.4.3/
# 确定没有错误后,执行make && make install
make && make install
# 使nginx命令全局生效
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
mv Nginx-Fancyindex-Theme-master/Nginx-Fancyindex-Theme-dark /usr/local/nginx/html/
mv Nginx-Fancyindex-Theme-master/fancyindex.conf /usr/local/nginx/conf/
- 编辑nginx.conf配置文件 把fancyindex.conf包含到location /中。
location / {
root html;
#autoindex on;
#autoindex_localtime on;
include fancyindex.conf;
allow all;
}
- fancyindex.conf文件。
fancyindex on;
fancyindex_localtime on;
fancyindex_exact_size off;
fancyindex_header "/Nginx-Fancyindex-Theme-dark/header.html";
fancyindex_footer "/Nginx-Fancyindex-Theme-dark/footer.html";
fancyindex_ignore "examplefile.html"; # Ignored files will not show up in the directory listing, but will still be public.
fancyindex_ignore "Nginx-Fancyindex-Theme-dark"; # Making sure folder where files are don't show up in the listing.
# Warning: if you use an old version of ngx-fancyindex, comment the last line if you
# encounter a bug. See https://github.com/Naereen/Nginx-Fancyindex-Theme/issues/10
fancyindex_name_length 255; # Maximum file name length in bytes, change as you like.
- 启动nginx
nginx -t #测试配置文件是否正确
nginx #启动服务
- 配置后会访问/usr/local/nginx/html 目录下的文件,将你需要展示的文件放在此目录下,然后访问nginx服务如下图: