---
title: "A folder without index.html lists every file: turn listing off"
description: "If a folder on your site has no index file and the server is allowed to build a listing, any visitor who opens it sees every file inside. On Nginx keep autoindex off, and on Apache remove Indexes with Options -Indexes."
url: https://ihsanalapsi.dev/articles/directory-listing-autoindex
lang: en
date: 2026-11-26
updated: 2026-11-26
tags: ["App security", "Web development"]
author: Ihsan Alapsi (إحسان العبسي)
---
# A folder without index.html lists every file: turn listing off

A small `index.html` file at the top of each folder decides whether a visitor sees a page or a list of every file in that folder: backups, old configuration files, and whatever your users uploaded. By the end of this article you will know why the server builds that list, how to check your site in a minute, and which line turns it off on Nginx and Apache.

## What is a directory listing?

A directory listing is a page the server builds on its own when someone requests a folder URL that has no index file, and it shows the names of every file and folder inside as clickable links.

It is like leaving the storeroom door open with nobody at the front desk: no one tells the visitor "the showroom is this way," so they walk in and see every shelf. On Nginx, [the autoindex module documentation](https://nginx.org/en/docs/http/ngx_http_autoindex_module.html) says the module processes requests ending with `/` and produces a directory listing, and that a request usually reaches it when the index module cannot find an index file.

## Why is that listing a risk to your site?

Because a file with no link on your site gets a link in the listing. What stayed hidden because nobody knew its name is now visible to anyone who opens the folder.

The mistake usually goes like this: a developer drops a database backup into a public folder to move it quickly, or an app stores user files in an `uploads/` folder, and nobody thought to put an `index.html` there. Nothing in the code is broken, and the server is doing exactly what it was told. But the attacker doesn't need to guess file names, because the server handed them the index.

And that points to the fix: if the listing is what exposes the names, turn it off in the server itself instead of chasing every folder.

## How do you check your site?

You check it by opening folder URLs yourself and searching the configuration for the line that turns the listing on.

1. In a browser, open the URL of every known folder on your site with a `/` at the end: the images folder, `uploads/`, `assets/`, and any folder you move files through. If a page of file names as links appears, listings are on.
2. On Nginx, search your configuration files for `autoindex on`. If you find it, ask why.
3. On Apache, search for `Indexes` in `Options` lines, in the server configuration and in `.htaccess` files.
4. If you find a file that shouldn't be public, delete it from the folder first. Turning off the listing hides the name, but the file still opens for anyone who knows its URL.

## How do you turn it off on Nginx?

On Nginx the listing is off unless someone turned it on: the same documentation says the default is `autoindex off`, and the directive goes in `http`, `server` or `location`.

So you don't need to add anything, you need to remove something. If you find `autoindex on` somewhere, set it back like this or delete the line:

```
location /uploads/ {
    autoindex off;
}
```

## How do you turn it off on Apache?

On Apache the listing comes from the `Indexes` option of the `Options` directive.

According to [the Options directive documentation](https://httpd.apache.org/docs/2.4/mod/core.html), if a URL maps to a directory with no DirectoryIndex such as `index.html`, `mod_autoindex` returns a formatted listing of the directory. The same page says the default was changed from `All` to `FollowSymlinks` in 2.3.11.

The line that turns it off:

```
<Directory "/var/www/html">
    Options -Indexes
</Directory>
```

Watch the sign. The documentation explains that options preceded by `+` or `-` are added to or removed from the options in force, while writing them without a sign replaces them all. Mixing the two forms on one line, such as `Options -Indexes FollowSymLinks`, is rejected by Apache at startup.

## Where do you start now?

The lesson for us as developers: a file hidden by its name is not a protected file, and a listing removes that cover with one request.

Open your site's `uploads/` folder in a browser now, and if a listing appears, turn it off with the right line for your server and delete every file that has no business there. When users upload files, [validating uploads](/articles/file-upload-validation) completes this step, and [error messages that leak details](/articles/error-handling-stack-traces) are the other door the same attacker uses. And if you want someone to test your whole platform, [Muhassan](/muhassan) does that. Which folder will you open first?

## FAQ

**Does Nginx show directory listings by default?**

No. The Nginx documentation says the default for autoindex is off, so a listing only appears if someone wrote autoindex on in the configuration.

**Is an empty index.html in every folder enough?**

It hides the listing in that folder only, and the first new folder without the file exposes it again. Turning it off in the server configuration is better.

**What is the difference between Options -Indexes and Options Indexes on Apache?**

The minus sign removes Indexes from the options in force and keeps the rest. Writing it without a sign replaces all the options with the ones you listed.
