Skip to content
STAGE33R

Guides · Server software · 6 steps · reviewed

Apache hardening on Linux: hide the version, turn off directory listings and fix TLS

A default Apache install tells visitors its exact version, lists the files of any folder without an index page, and loads modules most sites never use. None of that is a vulnerability by itself, but it helps an attacker choose the next step. These changes take about fifteen minutes and are safe if you test the configuration before reloading.

  1. Back up the configuration

    Keep a copy so you can return to the current state in seconds.

    sudo cp -a /etc/apache2 /root/apache2-backup-$(date +%F)
  2. Hide version details

    ServerTokens Prod sends only the word Apache in headers, and ServerSignature Off removes the footer on error pages. Put both in a small file that is enabled on its own.

    printf 'ServerTokens Prod\nServerSignature Off\nTraceEnable Off\n' | sudo tee /etc/apache2/conf-available/stage33r-hardening.conf
    sudo a2enconf stage33r-hardening
  3. Turn off directory listings

    Remove the Indexes option so a folder without an index file returns an error instead of a file list. Check which sites override it.

    sudo a2dismod -f autoindex
    grep -rn 'Options.*Indexes' /etc/apache2/ /var/www 2>/dev/null
  4. Disable modules you do not use

    List what is loaded and remove what the sites do not need, for example status, info, and cgi if no script uses it. Each module is code you must patch.

    apache2ctl -M | sort
    sudo a2dismod -f status info
  5. Allow only current TLS versions

    In the TLS configuration allow TLS 1.2 and 1.3 only, and let clients choose the cipher.

    # in /etc/apache2/mods-available/ssl.conf
    SSLProtocol -all +TLSv1.2 +TLSv1.3
    SSLHonorCipherOrder off
  6. Test, then reload

    configtest catches syntax errors before they take the site down. Reload applies the change without dropping connections.

    sudo apache2ctl configtest && sudo systemctl reload apache2
    curl -sI https://YOUR_DOMAIN | grep -i '^server'

Common mistakes

  • Disabling a module that a site quietly needs (rewrite, headers, proxy): test every site, not just the first.
  • Editing the main apache2.conf instead of a separate conf-available file, so the change is lost or overwritten at the next package update.
  • Removing Indexes from a site that relied on it as a download page.

How to undo it

Run sudo a2disconf stage33r-hardening, re-enable any module with sudo a2enmod NAME, restore /etc/apache2 from the backup if needed, then configtest and reload.

Sources

Commands are for Debian and Ubuntu unless noted. Test on a copy first and keep a backup: you are responsible for changes on your own systems.