change nginx auto index

How to Change NGINX AutoIndex

AutoIndex is a useful feature that allows you to browse and copy the files & folders located on a remote server. All popular servers such as Apache & NGINX support this feature. If you don’t want anyone to be able to view your content’s folder structure, you need to disable AutoIndex. By default, the autoindex feature loads an HTML page with file/folder list but if you want to display the same information in another format such as XML you need to change NGINX autoindex.


How to Change NGINX AutoIndex

Starting NGINX 1.7.9 this feature is available out of the box, using autoindex_format directive. Just add these two lines in your server configuration’s http block to enable XML format for file/directory listing.

autoindex on;
autoindex_format xml;

If you are using an older NGINX version, you can use Fancy Index NGINX module that allows you to :

  • Custom headers & footers (either local or stored remotely).
  • Custom CSS style rules.
  • Allow choosing to sort elements by name (default), modification time, or size; both ascending (default), or descending (new in 0.3.3).

This module needs to be compiled with source, during NGINX installation and cannot be added afterwards. Let us say you have downloaded NGINX tarball as per your requirement. Run the following command to unzip it.

$ gunzip -c nginx-?.?.?.tar.gz | tar -xvf -

Next, download latest version of fancy index from its git repository.

$ git clone https://github.com/aperezdc/ngx-fancyindex.git ngx-fancyindex

Then run the following command to change to the unzipped folder which contains NGINX source files, run configuration script with required options and use –add-module option to install additional modules.

$ cd nginx-?.?.?
$ ./configure --add-module=../ngx-fancyindex  [extra desired options]

Build and Install Software.

$ make
$ sudo make install

Once you have installed NGINX with fancy index module, you can enable it by adding the fancy_index directive in location block.

location / {
  fancyindex on;              # Enable fancy indexes.
  fancyindex_exact_size off;  # Output human-readable file sizes.
}

In this article, we have learnt a couple of ways to change NGINX autoindex. You can use either of the methods described above, as per your requirement.

Also read:

How to Manage User Password Expiry & Aging in Linux
How to Remove Yum Repositories
How to Undo or Redo Yum Install in RHEL/CentOS/Fedora
How to Fix Passwd Authentication Token Manipulation Error
How to Create Multiple User Accounts in Linux

Leave a Reply

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