Nginx custom autoindex without FancyIndex

Sending your friends an open directory in your site isn’t fun unless it has random ASCII art under it. :-)

Nginx lets one customise the look of open directories using the FancyIndex module. Unfortunately Debian Wheezy doesn’t include this module, unless you get nginx-extras from the wheezy-backports repository. As an alternative, I chose to hack up something in PHP for a similar effect.

Installation

Grab autoindex.phps, rename it to “autoindex.php” and place it in /your/domain/root/theopendirectory/.

Then, in the Nginx server{} block of your domain, put the following:

location /theopendirectory {
    rewrite ^/theopendirectory([^.]+)$ /theopendirectory/autoindex.php?path=$1 last; break;
}

Restart Nginx and your directory will be open and customisable by editing autoindex.php. :-)

Limitations

This being a quick and dirty ‘solution’, there are limitations:

  • Directory names with a dot in them are not supported
  • Files without a dot in them are not supported
  • Extremely long file names or sizes will mess up the listing a bit

Tags: | November 16th, 2014 | Posted in Uncategorized

Comments are closed.