0
0
Nginxdevops~30 mins

Directory listing (autoindex) in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Enable Directory Listing with Nginx Autoindex
📖 Scenario: You are setting up a simple web server using Nginx. You want visitors to see a list of files when they visit a folder without an index file.
🎯 Goal: Configure Nginx to show directory listings (autoindex) for a specific folder on your server.
📋 What You'll Learn
Create a server block configuration file for Nginx
Set the root directory to /var/www/html/files
Enable autoindex directive to show directory listing
Reload Nginx to apply the changes
Verify the directory listing is shown when accessing the folder
💡 Why This Matters
🌍 Real World
Web servers often need to show directory contents when no index file is present, such as for file sharing or downloads.
💼 Career
Knowing how to configure Nginx autoindex is useful for system administrators and DevOps engineers managing web servers.
Progress0 / 4 steps
1
Create Nginx server block configuration
Create a file called /etc/nginx/sites-available/files.conf with a server block that listens on port 80 and sets the root directory to /var/www/html/files.
Nginx
Need a hint?

Use server { ... } block with listen 80; and root /var/www/html/files;.

2
Enable autoindex directive
Inside the server block in /etc/nginx/sites-available/files.conf, add the line autoindex on; to enable directory listing.
Nginx
Need a hint?

Add autoindex on; inside the server block.

3
Create symbolic link to enable site
Create a symbolic link from /etc/nginx/sites-available/files.conf to /etc/nginx/sites-enabled/files.conf using the command ln -s /etc/nginx/sites-available/files.conf /etc/nginx/sites-enabled/files.conf.
Nginx
Need a hint?

Use ln -s command to create the symbolic link.

4
Reload Nginx and verify directory listing
Reload Nginx with sudo systemctl reload nginx and then access http://localhost/ in your browser to see the directory listing of /var/www/html/files. Write a print statement that outputs Directory listing enabled to confirm.
Nginx
Need a hint?

Use sudo systemctl reload nginx to reload and print("Directory listing enabled") to confirm.