Nginx文件服务器-FancyIndex插件美化教程

1.下载FancyIndex包:https://codeload.github.com/aperezdc/ngx-fancyindex/zip/master
2.将下载的zip包解压到nginx源码目录

unzip ngx-fancyindex-master.zip

3.编辑安装Nginx

yum -y install gcc-c++
yum -y install pcre-devel zlib-devel openssl-devel
./configure --prefix=/usr/local/nginx --add-module=./ngx-fancyindex-master
make && make install

4.下载fancyindex资源文件:https://github.com/TheInsomniac/Nginx-Fancyindex-Theme
5.下载后,解压到站点根目录

unzip Nginx-Fancyindex-Theme-master.zip
mv Nginx-Fancyindex-Theme-master fancyindex

6.配置Nginx配置文件,在location或者server中添加以下代码:

#autoindex on;
#autoindex_exact_size off;
#autoindex_localtime on;
fancyindex on;
fancyindex_localtime on; #on for local time zone. off for GMT
fancyindex_exact_size off; #off for human-readable. on for exact size in bytes
fancyindex_header "/fancyindex/header.html";
fancyindex_footer "/fancyindex/footer.html";
fancyindex_ignore "fancyindex"; #ignore this directory when showing list
fancyindex_default_sort date_desc; #以上传时间倒序排列

7.启动nginx

/usr/local/nginx/sbin/nginx -s stop && /usr/local/nginx/sbin/nginx

8.自定义footer.html信息(可选)

<!-- footer START -->
    <div id="footer">
        <a id="gotop" href="#" onclick="MGJS.goTop();return false;">回到顶部</a>
        <a id="powered" href="http://wordpress.org/">WordPress</a>
        <div id="copyright">
            版权所有 © 本页面由xxx提供 
        </div>
        <div id="themeinfo">
            <a href="http://www.example.com/about/">关于我们</a> | <a href="http://www.example.com/sitemap.html">网站导航</a> | <a href="http://www.example.com/sitemap.xml">网站地图</a> |<a rel="nofollow" href="http://www.example.com/">example公司</a>
        </div>
    </div>
<!-- footer END -->

9.使用php动态页面的nginx配置(可选)

...
	root /share;
    index index.php;

    location / {
        charset utf-8;
        #autoindex on;
        #autoindex_exact_size off;
        #autoindex_localtime on;
        fancyindex on;
        fancyindex_localtime on;
        fancyindex_exact_size off;
        fancyindex_header "/fancyindex/header.php";
        fancyindex_footer "/fancyindex/footer.php";
        # fancyindex_ignore "fancyindex";
        # fancyindex_default_sort date_desc;
        index index.php index.html index.htm;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location /favicon.ico {
        log_not_found off;
        access_log off;
    }
...
posted @ 2021-03-19 16:29  wanghongwei-dev  阅读(1181)  评论(0编辑  收藏  举报