DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
FREEDOM251

Freedom251 › Blog › autoindex

How to Hide Nginx Folder Contents on Ubuntu 24.04

By Freedom251 Team · · 7 min read

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To disable a generated directory listing, add autoindex off; to the active Nginx http, server, or location context that handles the affected URL, then reload Nginx with sudo systemctl reload nginx. Ubuntu 24.04 normally has autoindex disabled already, so an existing autoindex on; in the effective configuration is usually what you need to remove or override.

What Nginx directory listing is—and what disabling it changes

Nginx directory listing is the generated HTML page that shows filenames when a client requests a directory URL such as https://example.com/downloads/. The feature is controlled by the autoindex directive in Nginx’s autoindex module. Its documented form is autoindex on | off;, and its default is off.

As an Amazon Associate I earn from qualifying purchases.

Autoindex is generally involved only when the request ends with a slash and Nginx’s index processing cannot find an index file. It is different from serving a file whose name is already known. Turning it off therefore stops the generated listing; it does not prevent Nginx from serving an explicitly requested file, and it does not create an index page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Disabling the listing also does not guarantee a particular replacement response. Depending on the rest of the active configuration, the same directory may produce an index page, a 403 response, a 404 response, or another application-defined result.

Find the configuration that actually serves the URL

Edit the server block that handles the hostname and path where the listing appears. Changing an unused file has no effect, even if its contents look correct.

Single-site Ubuntu setup

Ubuntu’s documented single-site configuration is /etc/nginx/sites-enabled/default. Open that file and look for its server block and the location / block inside it. The exact layout can differ if the installation has been customized.

Multiple sites

For a multi-site installation, enabled configurations are represented by entries in /etc/nginx/sites-enabled/. The corresponding site files are commonly kept in /etc/nginx/sites-available/ and enabled by symlinking them into sites-enabled. Follow the enabled entry for the hostname that displays the listing, then edit its source file under sites-available rather than editing an unrelated virtual host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the narrowest scope that covers the problem

The autoindex directive is valid in http, server, and location contexts. Put it in the smallest applicable scope so that you do not unintentionally change behavior for other sites or paths.

Context Effect When to use it
location Controls listings for one matching URL path Best when only a directory such as /downloads/ needs changing
server Controls listings throughout one virtual host unless a more specific location changes it Useful when the entire hostname should never generate listings
http Sets the behavior across the HTTP configuration unless a lower-level context overrides it Use only when the policy should apply to all configured sites

Disable autoindex step by step

  1. Open the active site file. Start with /etc/nginx/sites-enabled/default for Ubuntu’s documented single-site arrangement. Otherwise, identify the enabled virtual host and open its matching file in /etc/nginx/sites-available/.
  2. Inspect the relevant blocks. Search the active configuration for autoindex on;. Also check parent http or server blocks if the affected location does not contain an explicit setting. A listing normally means that an enabled configuration has turned the feature on, because the default is off.
  3. Add an explicit off setting. Place the directive in the narrowest block that covers the affected path. For example:
server {
    # existing listen, root, server_name, and other directives

    location / {
        autoindex off;
        try_files $uri $uri/ =404;
    }
}

The important change in this example is autoindex off;. The try_files line is part of Ubuntu’s sample configuration pattern; it is not required merely to disable directory listings and should not be added blindly to a customized site.

If only one directory needs the change, use a matching location instead of changing the entire server:

location /downloads/ {
    autoindex off;
}

Do not leave two contradictory directives in the same effective scope and assume the one you edited is active. A more specific location or a different server block may be handling the request.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reload Nginx

  1. Save the file. Preserve the semicolon after the directive and keep the setting inside a valid Nginx block.
  2. Reload the service. Use Ubuntu’s documented reload command:
sudo systemctl reload nginx

A reload applies the configuration without the full stop-and-start operation associated with restarting the service. If your package or deployment is managed by another service supervisor, use that system’s documented reload procedure instead.

Verify the result with two different URLs

Check the change in a browser or HTTP client after the reload. Test both a directory that has no index file and a normal page that is supposed to use one. This distinguishes a successful autoindex change from a broader configuration mistake.

Test What it tells you Expected interpretation
A slash-ending directory URL with no index file, such as /downloads/ Whether Nginx still generates a listing No generated filename list should appear after autoindex off; is effective
A regular page URL expected to serve an index file Whether ordinary index processing still works The configured index page should continue to load
An explicitly named file URL Whether normal static-file serving is unaffected A known file can still be served even though a directory list is disabled

Do not use a directory that already contains an index page as your only test. In that case, Nginx may serve the page and never need to generate a listing, hiding whether autoindex is actually off.

Index files are a separate setting

Nginx’s index module handles index filenames independently of autoindex. The documented default index filename is index.html. Ubuntu’s sample server block lists index.html, index.htm, and index.nginx-debian.html.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Consequently, disabling autoindex does not make a blank directory display a custom welcome page. If you want a directory URL to show content rather than an error, provide an appropriate index file and configure the desired index names. If no index file is available, the response is determined by the remaining configuration; Nginx is not required to return 404 solely because autoindex is off.

Index processing can also trigger an internal redirect. After Nginx selects an index filename, the request may be processed by a different location block. That explains cases where the directory URL appears to use one set of rules but the resulting index page follows another location’s behavior.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot a listing that is still visible

You edited the wrong file

Recheck the hostname and path in the browser. A request may be handled by a different enabled server block than the Ubuntu default site. Inspect the entries in /etc/nginx/sites-enabled/ and follow the corresponding file in /etc/nginx/sites-available/. In a multi-site setup, adding autoindex off; to the default virtual host does not alter another site’s configuration.

A more specific location overrides your setting

A parent server setting can be superseded by a matching location, and a location setting can differ from a broader http policy. Place the directive in the location that actually matches the directory URL, or remove an explicit autoindex on; from that narrower block.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The browser is showing an old response

Request the exact slash-ending directory URL again after the reload. A cached page can resemble a current listing. Test with a separate browser session or HTTP client if necessary, and ensure you are checking the same hostname, scheme, and path that produced the original result.

The directory now returns an error

An error response after disabling autoindex can be the intended consequence of having neither a listing nor an index file. It does not by itself prove that the directive failed. Check whether the directory is supposed to serve an index page, whether the path is correct, and whether another location or access rule defines the response.

Normal pages stopped working

Compare a known-good page with the directory test. If ordinary pages fail, review the surrounding configuration you changed, especially any accidental edits to root, index, or try_files. The goal is to change the autoindex setting, not to rewrite the site’s file-resolution rules.

Ubuntu 24.04 version context

Ubuntu 24.04 LTS release notes identify Nginx 1.24 for that release. That is useful package context, but it is not a guarantee that every server has an untouched Ubuntu package: administrators may use a different repository, a container image, a compiled build, or a customized configuration. The autoindex directive remains an Nginx configuration setting; verify the effective files and service on the machine you administer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Operational checklist

  • Confirm the request ends with / and points to a directory without an index file.
  • Identify the enabled server block for the hostname and path.
  • Look for an existing autoindex on; in the applicable http, server, or location scope.
  • Add autoindex off; at the narrowest appropriate scope.
  • Save the correct site file and run sudo systemctl reload nginx.
  • Retest the directory URL and a normal index-file page separately.
  • If the result is unexpected, check for a different virtual host, a more specific location, an internal redirect to an index location, or the absence of an index file.

Once the active configuration contains autoindex off; and Nginx has been reloaded, generated directory listings are disabled for the covered scope. The response visitors receive afterward depends on the index files and other rules that remain in that server configuration.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

autoindexLinux administrationNGINXUbuntu 24.04web server

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.