Skip to content
Follow
Ubuntu Linux

Disable Apache Directory Listing on Ubuntu 24.04

Richard
Written by
Richard
Feb 19, 2025 Updated Sep 15, 2026 2 min read
Disable Apache Directory Listing on Ubuntu 24.04
Disable Apache Directory Listing on Ubuntu 24.04

Apache directory listing on Ubuntu 24.04 makes your server folders browsable for website visitors when an index page is missing. This feature, known as autoindexing in Apache version 2.4.58, exposes your file structure and leaves server contents open to public view.

Advertisement

Turning off this setting blocks unauthorized access and shows a 403 Forbidden error instead of a complete file list. You can stop directory browsing by updating your server settings to remove index permissions.

⚡ 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.

Advertisement

Disable directory listing

To disable Apache directory listing across your entire Ubuntu 24.04 server, open the main configuration file at /etc/apache2/apache2.conf in a text editor. Find the main directory block and remove the word Indexes from the options line. This stops visitors from seeing a list of your files when a webpage is missing.

Modifying the relevant block removes the `Indexes` keyword from the `Options` directive. Securing content within `/var/www/` requires changing the configuration block, saving the file, and restarting the service. Reverting this change involves adding `Indexes` back to the `Options` line.

Run the command below to open the global configuration file.

sudo nano /etc/apache2/apache2.conf

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

Advertisement
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
💡TipTo disable directory listing, remove 'Indexes' from the Options line.

Restricting directory listing for all content within the /var/www/ default directory requires modifying the block as shown below.

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

Save and exit the file.

Restart Apache to apply the new configuration.

Advertisement

Re-enabling directory listing happens at any time by adding 'Indexes' back into the configuration.

Disable directory listing selectively

To disable Apache directory listing for just one specific website instead of the whole server, add a custom block inside that site's individual configuration file. This lets you turn off file browsing for a single domain while keeping default settings for everything else on your Ubuntu 24.04 machine.

Review this example of a website configuration implementing the restriction.

<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 restricts behavior specifically for the /var/www/banking/ website within the broader Apache directory structure.

Advertisement

The server is now fully secured.

Keeping your server secure requires managing directory listing correctly.

  • 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.

Advertisement

📚 Related Tutorials

How to Enable or Disable Windows 11 Notifications
Windows How to Enable or Disable Windows 11 Notifications
How to install ProcessWire with Apache on Ubuntu 24.04
CMS How to install ProcessWire with Apache on Ubuntu 24.04
How to Set Up FileRun and Nginx on Ubuntu 24.04
CMS How to Set Up FileRun and Nginx on Ubuntu 24.04

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

Leave a Comment

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