Skip to content
Follow
Ubuntu Linux

Disable Apache Directory Listing on Ubuntu 24.04

Richard
Written by
Richard
Feb 19, 2025 Updated Jul 13, 2026 3 min read
Disable Apache Directory Listing on Ubuntu 24.04
Disable Apache Directory Listing on Ubuntu 24.04

Disabling Apache directory listing on Ubuntu 24.04 stops your web server from showing lists of files when no index page is found.

Apache directory listing, also known as ‘autoindexing,’ is a setting that automatically creates a page showing all the files in a folder on your website. This happens when a standard page, like ‘index.html,’ isn’t present in that folder.

Turning off this feature improves your website’s security by hiding your file and folder structure. For example, if you’re using Apache version 2.4.58 on Ubuntu 24.04, you’ll change a setting called `Options` to include `-Indexes`.

After you make this change, anyone trying to view a directory without an index file will see a ‘403 Forbidden’ error instead of a list of files. This prevents them from browsing your server’s contents.

⚡ Quick Answer

Edit your Apache configuration file, like `apache2.conf` or a virtual host file, and change `Options Indexes` to `Options -Indexes`. Save the file and restart Apache for the changes to take effect. This prevents Apache from automatically generating directory listings.

Disable directory listing

You can disable Apache directory listing for your entire server by editing the main Apache configuration file, typically located at `/etc/apache2/apache2.conf`. This global setting influences how Apache handles all websites hosted on your server. By altering the directory listing setting, you prevent Apache from showing file lists. On Ubuntu 24.04, Apache web servers have this directory listing feature enabled by default. This means visitors can see a list of files within a directory if no index file is found.

To disable it, locate the `Options` directive and remove the `Indexes` keyword. For instance, to affect all content within `/var/www/`, you’d modify the relevant block. Save the file and then restart Apache for the changes to take effect. You can always re-enable directory listing by adding `Indexes` back to the `Options` line.

Run the command below to open the global configuration file.

🐧Bash / Shell
sudo nano /etc/apache2/apache2.conf

This block, featuring the ‘Indexes‘ option, activates directory listing for Apache’s default root directory (/var/www).

💻Code
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

To disable directory listing, remove ‘Indexes‘ from the Options line.

If you want to disable directory listing for all content within the /var/www/ default directory, modify the block as shown below.

💻Code
<Directory /var/www/>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Save and exit the file.

Restart Apache to apply your changes.

You can re-enable directory listing anytime by adding ‘Indexes‘ back.

Disable directory listing selectively

To disable Apache directory listing for just one or a few websites, you need to add specific code to each site’s individual configuration file. This method is different from changing the main server settings and gives you control over directory listings on a site-by-site basis.

Here’s a basic example of a website configuration that disables directory listing.

💻Code
<VirtualHost *:80>
ServerName banking.example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/banking

<Directory /var/www/banking/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

This configuration will only affect the /var/www/banking/ website within Apache’s directory structure.

That should do it!

Conclusion:

  • Enabling or disabling Apache directory listing is crucial for maintaining server security.
  • Disabling directory listing prevents unauthorized access to files and sensitive information within directories.
  • Users without an index file will encounter a 403 Forbidden error, enhancing security.
  • Configurations can be made globally or selectively for individual websites, providing flexibility.
  • Always restart Apache after making changes to ensure they take effect.
  • Regularly review and update your server configurations to keep security measures current.

Was this guide helpful?

50% of readers found this helpful (2 votes)

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Enable or Disable Windows 11 Notifications
Windows How to Enable or Disable Windows 11 Notifications

No comments yet — be the first to share your thoughts!

Leave a Comment

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