autoindex_format
The 'autoindex_format' directive defines the format of the directory listings generated by the autoindex module in NGINX.
Description
The autoindex_format directive specifies the output format of directory listings when the autoindex feature of NGINX is enabled. This directive allows users to alter the appearance of the generated HTML for better readability or customization purposes. NGINX supports a couple of predefined formats such as html and json, each serving a different presentation style. When the directive is set in the configuration file, it instructs NGINX to use the specified output format instead of falling back to the default configuration, enhancing the usability of directory indexes for clients or applications that may rely on specific data structures in the response.
In practical scenarios, the autoindex_format can be leveraged to provide a user-friendly presentation of directory contents with HTML, such as including links and file sizes, or in JSON format for API consumption, which can be easily parsed programmatically. The format must be set within valid contexts, namely at the http, server, or location level, allowing for comprehensive control depending on the scope of the NGINX configuration. This directive primarily supports integration with various client applications that process directory listings differently based on their expected format.
Config Example
location /files {
autoindex on;
autoindex_format json;
}Ensure that the autoindex module is enabled using 'autoindex on;' before using this directive.
Specifying an unknown format results in an error; use only supported formats.