Better Autoindex with nginx/php

Using capability of nginx.

Basically, add this block

        location @lister
        {
                fastcgi_pass unix:/tmp/php-fcgi.sock;
                fastcgi_param PREFIX $_list_prefix;
                fastcgi_param FILE_ROOT $_list_root;
                fastcgi_param SCRIPT_FILENAME /srv/http/lister.php;
                include fastcgi_params;
        }

(adjust the path to lister.php and php-fcgi)

And then whenever you want to autoindex a folder just add

        location /anime/win/ {
                set $_list_prefix /anime/win;
                set $_list_root /srv/ftp;
                alias $_list_root/;
                try_files $uri @lister;
        }

And you’re done.

The code still needs some cleanups though.

[ lister.php ]

4 thoughts on “Better Autoindex with nginx/php

Leave a Reply

Your email address will not be published. Required fields are marked *