民审-M

Nginx编译安装Fancy Index模块,实现漂亮的索引目录

作者:民审-M   发布时间:2016-08-25 09:16   回复数:0   浏览数:364
民审-M
3640民审-M金牌草根
2016-08-25 09:16:36
3640 2016-08-25 09:16:36
[color=rgb(51, 51, 51)]<p align="left">Nginx开启目录浏览配置文件,便可轻松的实现Nginx索引,不过自带的索引目录不是特别美观,也不可以自定义,我们可以安装第三方Fancy Index模块,来实现漂亮的索引目录。</p><p align="left"></p><p align="left">此方法适用于OneinStack(LNMP)环境下编译安装Fancy Index模块,当然原理和方法类似,都可以参考。</p>一、下载模块
<p align="left">如果您已经安装好OneinStack(LNMP)一键包,默认情况是没有编译Fancy Index模块的,我们需要自己编译一下。</p>cd /root/lnmp/src                      ###进入LNMP一件包的src目录,请根据实自己的实际情况调整
git clone https://github.com/aperezdc/ngx-fancyindex.git ngx-fancyindex     ###下载Fancy Index模块二、解压Ningx
<p align="left">Nginx的包也是在/root/lnmp/src目录下,使用下面的命令解压,注意:不同的版本nginx压缩包名字可能不一样,请根据实际情况修改。</p>tar -zxvf nginx-1.9.14.tar.gz           ###解压nginx
cd nginx-1.9.14                         ###进入nginx目录三、增加Nginx模块
<p align="left">先输入命令nginx -V查看当前已经编译的模块,并记录。</p><p align="left"></p><p align="left">执行下面的命令在末尾增加--add-module=../ngx-fancyindex模块:</p>./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-ld-opt='-ljemalloc' --add-module=../ngx-fancyindex四、重新编译
<p align="left">依次输入下面的命令重新编译下nginx</p>make
mv /usr/local/nginx/sbin/nginx{,_`date +%F`}
cp objs/nginx /usr/local/nginx/sbin五、添加配置
<p align="left">将下面的配置文件添加到nginx主机配置文件中,并service nginx restart重启nginx</p>location / {
fancyindex on;
fancyindex_exact_size off;
fancyindex_localtime on;
#fancyindex_header \&quot;/header.html\&quot;;
fancyindex_footer \&quot;/footer.html\&quot;;
fancyindex_ignore \&quot;footer.html\&quot; \&quot;exclude_centos.list\&quot;;
}
<p align="left">这样就可以利用Fancy Index模块模块美化Nginx索引目录啦,也可以自定义footer或者header页面,分享一下自己的footer.html文件:</p>&lt;style type = \&quot;text/css\&quot;&gt;
                body{
                        margin:0;
                        padding:0;
                        font-size:16px;
                        font-family:'MicrosoftYaHei';
                }
                #foot{
                        font-size:14px;
                        width:100%;
                        position: fixed;
                        bottom:10px;
                        text-align:center;
                        padding:8px;
                        padding-top:20px;
                        /*border:1px solid red;*/
                        margin-top:20px;
                }
                a{
                        text-decoration:none;
                }
        &lt;/style&gt;
 
        &lt;div id = \&quot;foot\&quot;&gt;
                &amp;#169;2016 Powered by &lt;a href = \&quot;https://www.cgzz8.cn/\&quot; title = \&quot;草根吧\&quot; target = \&quot;_blank\&quot;&gt;草根吧&lt;/a&gt;. &lt;a href = \&quot;../readme.html\&quot; title = \&quot;草根吧 - Discuz应用中心\&quot;&gt;使用说明&lt;/a&gt;
        &lt;/div&gt;
        &lt;script src = \&quot;https://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js\&quot;&gt;&lt;/script&gt;
        &lt;script&gt;
                $(document).ready(function(){
                        var bodyheight = $(document.body).outerHeight(true);
                        var bheight = $(window).height();
                        //alert('body:' + bodyheight + 'browser:' + bheight);
                        if(bodyheight &gt; bheight) {
                                $(\&quot;#foot\&quot;).css(\&quot;position\&quot;,\&quot;relative\&quot;);
                        }
                });
        &lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;六、效果演示
<p align="left">最后查看到的效果如下图所示,</p><p align="left"></p>

游客
登录后才可以回帖,登录 或者 注册