Enable customization index page for nginx

Server Norckon 1662℃ 0评论



The default index page can only show directories or files. Is very simple page. But in sometimes, I want add some information or let index page more pretty. In this time, I need a extra on nginx called FancyIndex.

FancyIndex allows some customization of the fancy index pages:

  • Custom headers. (local or stored remotely)
  • Custom footers. (local or stored remotely)
  • Use your own CSS style rules.
  • Allow choosing to sort elements by name (default), modification time, or size.


There was two way to install on your server. One way is install nginx thought Software Source, the another way is compiled from Source Code.

Install FancyIndex for different ways installed nginx, its methods are not the same.

1. My nginx is compiled from source code

This a example for how to install a nginx with fancyindex from source code.

$ yum install gcc gcc-c++ make openssl openssl-devel
wget http://sourceforge.net/projects/pcre/files/pcre/8.33/pcre-8.33.tar.gz
tar -zxvf pcre-8.33.tar.gz
cd pcre-8.33
make && make install
cd ../

groupadd www
useradd -s /sbin/nologin -g www www
git clone https://github.com/aperezdc/ngx-fancyindex.git ngx-fancyindex

wget http://nginx.org/download/nginx-1.6.0.tar.gz
tar zxvf nginx-1.6.0.tar.gz
cd nginx-1.6.0/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --add-module=../ngx-fancyindex
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
git clone https://github.com/ixbear/nginx
mv nginx/nginx.conf /usr/local/nginx/conf/
mv nginx/init.d.nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig --level 345 nginx on
/etc/init.d/nginx start

NOTE: If system returned error message

error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

please do run command ln -s /usr/local/lib/libpcre.so.1 /lib64 first.

2. My nginx is installed from software source

If you install nginx for software source on Ubuntu or Debian server, Just need install a new package called nginx-extras by command sudo apt-get install nginx-extras.


To enable FancyIndex for your virtual host, you need add FancyIndex directives to your virtual host configuration file location section.

Configuration Example:

server {
	listen 443 ssl;
	server_name  lib.fcsys.org;
	location / {
		fancyindex on;				# Enable FuncyIndex
		fancyindex_exact_size off;		# off: Use GB / MB / KB etc.
		fancyindex_localtime on;		# on: Use server local time
		fancyindex_header /.header.html;	# Customization Header Code
		fancyindex_footer /.footer.html;	# Customization Footer Code

Header Example:

<body onload="ngx_onload()">
<h1 id="top2">Directory listing of

Footer Example:

More Informations Here.


The final step is reload nginx configuration by command nginx -s reload. Refresh your index page and take effect, your page may look like http://lib.fcsys.org.



Pekaikon Norckon

喜欢 (0)
Cancel Comment

Hi, We need some information

  • Nickname (*)
  • E-Mail (*)
  • Website
  1. 着实不错
    小成2015-08-04 18:34 Reply