How to Compile and Install Nginx Fancy Index Module for Beautiful Directory Listings
As mentioned in the FAQ section of Xiaoz Blog, enabling directory browsing in Nginx is straightforward, but the default index view is not very attractive and lacks customization options. To achieve a beautiful directory listing, you can install the third-party Fancy Index module.

This method is suitable for compiling the Fancy Index module in a OneinStack (LNMP) environment. The principles and methods are similar for other setups.
1. Download the Module
If you have already installed the OneinStack (LNMP) package, the Fancy Index module is not compiled by default. You need to compile it yourself.
cd /root/lnmp/src # Enter the LNMP package src directory; adjust according to your actual situation
git clone https://github.com/aperezdc/ngx-fancyindex.git ngx-fancyindex # Download the Fancy Index module
2. Unpack Nginx
The Nginx package is also located in the /root/lnmp/src directory. Use the following command to unpack it. Note that the Nginx archive name may vary depending on the version; please modify it according to your actual situation.
tar -zxvf nginx-1.9.14.tar.gz # Unpack Nginx
cd nginx-1.9.14 # Enter the Nginx directory
3. Add the Nginx Module
First, run the command nginx -V to check the currently compiled modules and record them.

Execute the following command to add the --add-module=../ngx-fancyindex module at the end of the configuration:
./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
4. Recompile
Run the following commands sequentially to recompile Nginx:
make
mv /usr/local/nginx/sbin/nginx{,_`date +%F`}
cp objs/nginx /usr/local/nginx/sbin
5. Add Configuration
Add the following configuration snippet to your Nginx host configuration file, and then restart Nginx using service nginx restart.
location / {
fancyindex on;
fancyindex_exact_size off;
fancyindex_localtime on;
#fancyindex_header "/header.html";
fancyindex_footer "/footer.html";
fancyindex_ignore "footer.html" "exclude_centos.list";
}
You can now use the Fancy Index module to beautify your Nginx directory listings. You can also customize the footer or header pages. Below is an example of my footer.html file:
<style type="text/css">
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;
}
</style>
<div id="foot">
©2016 Powered by <a href="https://blog.xiaoz.org/" title="Xiaoz Blog" target="_blank">Xiaoz Blog</a>. <a href="../readme.html" title="Xiaoz Blog - Software Library User Guide">User Guide</a>
</div>
<script src="https://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
var bodyheight = $(document.body).outerHeight(true);
var bheight = $(window).height();
//alert('body:' + bodyheight + 'browser:' + bheight);
if(bodyheight > bheight) {
$("#foot").css("position","relative");
}
});
</script>
</body>
</html>
6. Demo
The final result is shown in the image below. You can also visit the Xiaoz Blog Software Station at http://soft.hixz.org/ to view it. Note: Some content is referenced from the author's blog: https://blog.linuxeye.com/409.html.
