How to enable file browser mode in Nginx?

Updated on September 2, 2017

By default Nginx directory listing is disabled which is always recommended. Even then, we need to have directory listing for specific purpose and you can still enable. HttpAutoIndexModule is the module that handles the Nginx directory listing.

Note: autoindex is enabled by default. So if nginx -V command doesn’t show –without-autoindex, then it’s understood that autoindex is enabled.

Also read: Find out the flags used in Apache/Nginx/PHP compilation

On any location context, just add autoindex on, as shown below:

location / {
root /usr/share/nginx/html;
index index.html index.htm;
autoindex on;
}

Now when a directory is requested, the request only reaches the ngx_http_autoindex_module when ngx_httpd_index_module did not find an index file. Once the request reaches ngx_http_autoindex_module, it lists one or more files contained in that directory as shown below:

nginx directory listing

There are other 2 interesting options; autoindex_exact_size and autoindex_localtime as shown below:

location / {
root /usr/share/nginx/html;
index index.html index.htm;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}

autoindex_exact_size defines how to represent file sizes in the directory listing. By default it is “on”. ie., it shows the file sizes accurately in bytes. If made “off”, the files size shown will be rounded to KB, MB or GB

autoindex_localtime shows files time as localtime. Default is “off” (GMT time).

Was this article helpful?

Related Articles

Leave a Comment