A default Apache install is reasonably safe out of the box, but “reasonably” is the wrong adjective for a production server. The hardening pass below is what we apply to every Apache host before traffic flows — small changes individually, but they remove fingerprinting, narrow the loaded module set, lock down TLS, and add the response headers that prevent a whole class of browser-side attacks. This article is the checklist plus the verification each item.
How to verify
Before you start, snapshot the current state — server tokens, loaded modules, TLS protocols, and security headers — so the after-vs-before is visible:
curl -sI https://example.com/ | grep -iE 'server|x-powered-by|strict-transport|content-security|x-frame|referrer'
apachectl -M | sort
sudo apache2ctl -t -D DUMP_RUN_CFG | grep -iE 'tokens|signature|tracesendoff|protocols'
nmap --script ssl-enum-ciphers -p 443 example.com 2>/dev/null | tail -30
The first curl line surfaces fingerprinting headers and existing security headers. The nmap line lists every cipher Apache will negotiate — anything weak should be removed.
What’s happening
Hardening is layered:
- Identification layer — strip the version and module names from the
Serverheader. - TLS layer — modern protocols and ciphers, no weak ones.
- HTTP response headers — HSTS, CSP, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy.
- Module surface — disable everything not actively used.
- Filesystem permissions — root owns the binary and config; logs are not world-readable; vhost roots have predictable ownership.
- Module-specific —
mod_userdiroff,mod_status/mod_inforestricted,mod_trace/TraceEnable Off, ModSecurity in place if exposed to the public.
Each item is small. The compound effect is meaningful — fewer fingerprintable signals, fewer protocol downgrade options, fewer enabled-by-default endpoints that leak information.
The procedure
-
Lock the server tokens. In
/etc/apache2/conf-enabled/security.conf:ServerTokens Prod ServerSignature Off TraceEnable OffServerTokens Prodreduces theServerheader to justApache.ServerSignature Offremoves the trailing line on auto-generated error pages.TraceEnable Offdisables the HTTP TRACE method, which has no legitimate use in production. -
Disable unused modules. Audit the loaded set against what the workload actually needs:
sudo a2dismod status info userdir cgi autoindexRe-enable only the ones the application requires.
mod_userdir(serves~user/URLs from home directories) is rarely needed and surfaces user enumeration. -
Configure TLS to the modern profile. Replace the default
/etc/apache2/conf-enabled/ssl-params.conf(or your equivalent) with:SSLProtocol -all +TLSv1.2 +TLSv1.3 SSLCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256 SSLHonorCipherOrder on SSLCompression off SSLSessionTickets off SSLOptions +StrictRequire SSLUseStapling On SSLStaplingCache "shmcb:logs/stapling-cache(150000)"For TLS 1.3, the cipher suites are negotiated by the protocol — the
SSLCipherSuiteabove applies to TLS 1.2. Disable TLS 1.0 and 1.1 outright; both are deprecated. -
Add security headers. In every HTTPS vhost (or globally if no vhost-specific differences):
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" Header always set X-Content-Type-Options "nosniff" Header always set X-Frame-Options "DENY" Header always set Referrer-Policy "strict-origin-when-cross-origin" Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()" Header always set Content-Security-Policy "default-src 'self'; img-src 'self' data: https:; script-src 'self'; style-src 'self' 'unsafe-inline'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'"HSTS preload (
preloaddirective) commits the domain to HTTPS-only across major browsers — only enable after confirming the entire domain and subdomains work over HTTPS. CSP is the hardest to tune; start with a permissive policy and tighten via the report-only header until the violations stop. -
Lock down file permissions. The config directory is root-owned, log directory is
root:adm-owned:sudo find /etc/apache2 -type d -exec chmod 750 {} \; sudo find /etc/apache2 -type f -exec chmod 640 {} \; sudo chown -R root:root /etc/apache2 sudo chmod 750 /var/log/apache2 sudo chown root:adm /var/log/apache2Make sure your CM tool re-applies these on every run — package upgrades sometimes reset permissions.
-
Restrict mod_status and mod_info if enabled. If you need them for monitoring, limit to localhost or a management network:
<Location /server-status> SetHandler server-status Require local Require ip 10.0.0.0/24 </Location>Never expose
server-statusorserver-infoto the public — both leak request data and module configuration. -
Set sane request limits. Defend against oversized requests and slow-loris:
LimitRequestBody 10485760 # 10 MB LimitRequestFields 100 LimitRequestFieldSize 8190 LimitRequestLine 8190 Timeout 60 KeepAliveTimeout 5 -
Run a scanner. After all changes, validate from outside:
curl -sI https://example.com/ | grep -iE 'server|strict|content-security|x-frame|x-content' testssl.sh --severity HIGH https://example.com 2>/dev/null | grep -i 'vulnerable\|severity'testssl.shfrom drwetter/testssl.sh is the standard external scanner for TLS posture.
Common pitfalls
- A misconfigured CSP breaks the site silently (no visible errors, just resources blocked) — start in
Content-Security-Policy-Report-Onlymode, watch the report, then flip to enforcing. Header always set(vsHeader set) is the right form for security headers — withoutalways, the header is not added to error responses, where it matters most.- HSTS
max-ageis sticky in browsers; settingmax-age=0does not immediately remove the binding, only stops new sets. Test on staging before pushing to production. - Disabling
mod_statusremoves the monitoring endpoint Prometheus and similar scrapers use — coordinate with monitoring before disabling. - A scanner showing TLS 1.0 or 1.1 enabled despite
-TLSv1 -TLSv1.1usually means a vhost overrides the globalSSLProtocol— check allSSLProtocollines in/etc/apache2/.
Stack Harbor applies this hardening pass as a baseline on every Apache host we onboard, with the configuration kept under CM so drift is visible. The checklist above is the starting point; the full pass also includes ModSecurity tuning, intrusion detection, and quarterly TLS posture review. If your Apache fleet has not been through a hardening pass recently, that audit is part of the Managed Operations onboarding.