Disable Directory Listing on nginx, Apache, Node and Vercel (2026)

On a fresh Ubuntu 24.04 box we installed Apache 2.4.58, dropped one file into /var/www/html/uploads/ and requested the folder. Apache answered 200 with a page titled Index of /uploads, a "Parent Directory" link and the file name, size and upload time. No config changes. The stock apache2.conf ships Options Indexes FollowSymLinks for /var/www/, so every folder without an index.html is a public file browser.

Then we added the fix most guides give, Options -Indexes in .htaccess. Still 200. Same config file, same block: AllowOverride None, so Apache never reads the .htaccess at all.

TL;DR

Request /uploads/ (or any folder with files and no index.html) on your live site. If you get a page of file links, listing is on. Turn it off in the server config: Options -Indexes on Apache, remove autoindex on on nginx, drop browse on Caddy, -d false or directoryListing: false on Node static servers, the Directory Listing toggle on Vercel. Then remember that turning it off only hides the list: every file is still downloadable by its exact name.

What our scanner flags, and what it misses

CheckYourVibe's directory listing check runs on Pro scans. It requests 13 common folders: /images/, /uploads/, /static/, /assets/, /media/, /files/, /public/, /data/, /backup/, /backups/, /temp/, /tmp/ and /logs/. For each one that answers 200, it reads the first 3,000 characters of the body and looks for a listing signature: Index of /, Directory listing for, Parent Directory, [To Parent Directory] or Directory Listing. A match is reported as Directory Listing Enabled: /uploads/ (or whichever path), rated Medium, with the matched string as evidence.

Those strings match the default pages of nginx, Apache, IIS, Python's http.server and the http-server npm package. We ran eight setups locally against the same folder to see which ones list by default and which ones the check recognises:

Server (version tested)GET /uploads/, no index fileFlagged by our check
nginx 1.24, stock config403 ForbiddenNo listing to flag
nginx 1.24 with autoindex on200, "Index of /uploads/"Yes
Apache 2.4.58, stock Ubuntu config200, "Index of /uploads"Yes
python3 -m http.server (3.11)200, "Directory listing for /uploads/"Yes
http-server 14.1.1, defaults200, "Index of /uploads/"Yes
serve 14.2.7, defaults200, "Files within .../uploads/"No
Express 4.22.3, express.static only404No listing to flag
Express 4.22.3 + serve-index 1.9.2200, "listing directory /uploads/"No

Two of the six setups that listed the folder use wording our check doesn't match. If you're on serve or serve-index, don't read a clean scan as proof. Run the curl in Step 1 yourself.

Step 1: Confirm it from outside

1

Request a folder, not a file. Pick one that holds files and has no index.html:

curl -s https://yoursite.com/uploads/ | head -20
curl -s https://yoursite.com/backup/ | head -20
2

Read the body, not the status code. A single-page app often answers every path with 200 and its homepage, which is fine. A listing is a page of links to file names, usually titled "Index of", "Directory listing for", "Files within" or "listing directory".

3

Try the folders your app actually uses. Our check only knows the 13 common names above. If your app writes to /exports/ or /invoices/, request those too.

Step 2: Turn it off for your server

Apache

Put it in the main config or the vhost, where it can't be ignored:

/etc/apache2/apache2.conf (or your vhost)
<Directory /var/www/>
    Options FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

That's the stock Ubuntu block with Indexes removed. After apache2ctl graceful, our /uploads/ request went from 200 to 403. Per the Apache core docs, Indexes is the option that makes mod_autoindex "return a formatted listing of the directory" when there's no DirectoryIndex file, and Apache's own compiled-in default is Options FollowSymlinks. The listing you're seeing came from a distro or host config that added it back.

On shared hosting where you only control .htaccess, Options -Indexes works, but only if the host allows it. We confirmed both halves: with AllowOverride None the .htaccess line did nothing, and with AllowOverride Options it returned 403.

Don't write Options -Indexes FollowSymLinks. The core docs say mixing options with and without +/- "is not valid syntax and will be rejected during server startup". Use all prefixed (-Indexes +FollowSymLinks) or none.

nginx

nginx doesn't list folders unless someone asked it to. The autoindex module docs give the default as autoindex off;, and our stock 1.24 install returned 403 for /uploads/. So the fix is to find the line that turned it on:

grep -rn autoindex /etc/nginx/

Delete it, or scope it off for the folders that matter. autoindex is valid in http, server and location, and an inner block wins:

nginx
location /uploads/ {
    autoindex off;
}

With autoindex on at the server level and that block added, /uploads/ returned 403 and /backup/ kept listing. That's why deleting the server-level line beats patching folders one at a time. Run nginx -t && nginx -s reload and repeat the curl.

Caddy

file_server alone doesn't list. The browse subdirective is what "enables file listings for requests to directories that do not have an index file". If your Caddyfile says file_server browse, change it to file_server.

Node static servers (serve, http-server, Express)

These come up constantly in AI-built projects because they're one command to start, and two of them list by default.

serve renders a listing for any folder without an index, per the serve-handler docs. Add a serve.json next to your files:

serve.json
{ "directoryListing": false }

That turned our /uploads/ from 200 into 404. Running serve -s (single-page mode) also stopped the listing, because every unknown path falls back to index.html.

http-server lists by default; its README shows -d "Show directory listings" defaulting to true. Start it with -d false, which gave us a 403.

Express doesn't list unless you added serve-index, the middleware that exists to "serve pages that contain directory listings". Search your server file for serveIndex and delete it. express.static on its own returned 404.

python3 -m http.server lists every folder without an index.html and has no switch to stop it. Python's docs say it plainly: "http.server is not recommended for production." If it's serving your live site, replace it.

Vercel

Vercel has a project setting for this. Its Directory Listing docs put the toggle under Advanced in the project settings; when disabled, folders return a 404. The same page carries a catch worth knowing: a custom 404 page does not stop the listing, because "when the directory contains files, Vercel displays the Directory Listing instead of the 404 page." Flip the toggle, then redeploy and curl.

S3 and Google Cloud Storage

Buckets don't render "Index of" pages. They return XML, and our check doesn't look for it. On S3, listing a bucket needs the s3:ListBucket permission (ListObjectsV2) and the response is a <ListBucketResult> document naming every key. If your public bucket policy grants s3:GetObject and also s3:ListBucket (or s3:*) to "Principal": "*", remove the list permission.

On GCS the trap is the role name. Storage Object Viewer includes storage.objects.list and "can also list the objects in a bucket". If you made a bucket public by granting that role to allUsers, anyone can enumerate it. Storage Legacy Object Reader carries only storage.objects.get.

Step 3: Assume the list was already read

Turning listing off hides the index. It doesn't hide the files. On nginx, Apache and serve, after we disabled the listing, /uploads/invoice-1042.pdf still came back 200. Anyone who saw the listing last week has the names.

So the real question is what was in those folders:

  • Backups, dumps, logs. /backup/db-2026-11-01.sql has no business in a web root, listed or not. Move it out of the served folder entirely, and treat any credentials in it as exposed.
  • User uploads with guessable names. invoice-1042.pdf invites someone to try invoice-1041.pdf. If users upload private files, serve them through a route that checks who's asking, and store them under random names. Multer's disk storage already does this unless you override it: the multer README says each file gets "a random name that doesn't include any file extension". AI-generated upload code often swaps that for file.originalname, which puts the user's own file name, and any collisions, straight into your public folder.
  • Build leftovers. .map files, .env copies and config files that ended up in public/. Those have their own fixes: see source maps and the exposed .git guide.

If your access logs go back far enough, grep them for requests to the folder itself (GET /uploads/ ) from outside your own IPs. That tells you whether anyone actually looked.

How do I check if directory listing is enabled on my site?

Request a folder that has files but no index.html, such as https://yoursite.com/uploads/, and read the body. A page titled "Index of /uploads/", "Directory listing for /uploads/" or "Files within uploads", with links to each file, means listing is on. A 403, a 404 or your normal homepage means it isn't.

Is directory listing a security vulnerability?

It's a misconfiguration that turns guessable file names into a published index. On its own it only reveals names, but those names are usually the hard part: backups, logs, invoices and user uploads become one click away. We rate it Medium.

I added Options -Indexes to .htaccess and nothing changed. Why?

Apache ignores .htaccess entirely when AllowOverride is None, which is the stock setting for /var/www on Ubuntu. Either put Options -Indexes in the main config or vhost, or allow overrides with AllowOverride Options (or All) for that directory.

Does disabling directory listing hide my files?

No. It only stops the server from generating the list. In our tests on nginx, Apache and serve, a file requested by its exact name still returned 200 after listing was off. Anything that shouldn't be public has to be moved out of the web root or put behind auth.

Does adding an index.html to the folder disable directory listing?

For that one folder, yes, on every server we tested and on Vercel. It's a fine stopgap but it doesn't cover subfolders or new folders, so turn the listing off in the server config too.

Our scan probes your live site for exposed .env files, .git folders and backup dumps. Pro scans also request 13 common folders and flag any that list their files.

How-To Guides

Disable Directory Listing on nginx, Apache, Node and Vercel (2026)