How to enable directory listing in Nginx

Enabling the Nginx Directory Index Listing

Nginx is a popular web server that can also be used as a reverse proxy, caching, load balancing, and for other purposes. In this post, I'll show you how to enable and disable directory listing.

When an index file (such as index.html or index.php) is not found, NGINX will automatically generate and display a list of files in the directory. This occurs when a user navigates to a directory on a web server and there is no default file for that directory.

For example, if you do not have an index.html file in your server's docs directory, when someone visits, NGINX will generate a list of files and subdirectories within the docs' directory and display it in the web browser. This feature is useful for file sharing or providing a directory listing of documents or media files. It can, however, pose a security risk if sensitive information is exposed.

If you are using the Nginx web server and want to display folders in Nginx by web, you can use the autoindex directive in your NGINX configuration to enable or disable directory listing." in your conf file. By default, we cannot open a directory from the Nginx web.

Enable directory listing: Open your nginx conf file and change.

server {
        listen 80 default_server;
        listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
        autoindex on; #for enable directory listing 
        server_name _;

        location / {
  try_files $uri $uri/ =404;


How to disable Directory Indexing in Nginx. 

Here is the simple step to disable directory listing in Nginx. Go to the Nginx configuration file and turn off the indexing.

autoindex off;

Here is the video link of the tutorial.


If you enjoyed this post and found it useful, please buy me a coffee using this link : 😀
You might be interested in this article :How to setup Nginx ingress using helm

Vishal Vyas [Linux Guru]

Welcome to Linux Guru! Hello, friends. My name is Vishal Vyas, and I am a DevOps engineer with expertise in Linux and Cloud Computing. I am also a Certified Kubernetes Administrator with over 12 years of experience in the IT field, working with various technologies. Through this blog, I aim to share my technical knowledge on Linux, AWS, DevOps, and web technologies. I will be posting about what I have learned from the latest web technologies and similar topics.

Post a Comment

If you have any doubts, Please let me know

Previous Post Next Post