Security hardening guides

Web Server Hardening Checklist for Nginx and Apache

Harden Nginx and Apache with controlled web roots, TLS, safe proxy settings, upload isolation and request limits. Includes deployment and verification checks.

A web server hardening checklist should reflect how the application is deployed. The relevant controls differ between a static site, a PHP application and a reverse proxy serving several backends. Start with a map of the request path so that each setting has a clear owner.

Record the supported server version, operating system, TLS termination point, application runtime and public hostnames. Include direct origin addresses and management interfaces that might bypass the normal CDN or load balancer.

Keep the public directory deliberately small

Only expose files intended for public delivery. Put application configuration, source repositories, credentials, database exports, logs and backups outside the document root. A file named with an unusual extension can still disclose its contents when requested directly.

Disable directory listing unless the service explicitly needs it. In Nginx, use autoindex off; in the relevant context. In Apache, Options -Indexes disables generated listings. These settings do not protect a sensitive file whose exact path is known, so verify both listing and direct retrieval.

Restrict executable content

For PHP, send only intended script paths to PHP-FPM and reject script requests for files that do not exist. Keep upload storage outside that execution path. Separate application processes and filesystem permissions where several sites share a host.

Remove unused modules, example applications, status endpoints and diagnostics. Where operational endpoints are necessary, limit their audience and authentication rather than relying on an obscure URL.

Establish reliable HTTPS

Serve the intended hostnames with valid certificates and renew them through a monitored process. Configure supported TLS versions and verify the public edge as well as backend TLS where it is used. Redirect ordinary HTTP traffic to the intended HTTPS origin.

Introduce HSTS after the service works consistently over HTTPS. Including subdomains or requesting preload needs a separate review because it affects more than the current virtual host. Keep a recovery plan for certificate or routing failures.

Review reverse proxy trust

Only trust forwarded client addresses and scheme headers from known upstream proxies. Otherwise an attacker can influence decisions that rely on client IP or perceived HTTPS. Validate allowed hostnames and ensure backend services cannot become unintended open proxies.

Where a CDN or access gateway is intended to protect the origin, confirm that direct origin requests are restricted appropriately. A strong edge rule provides limited protection if the same application remains available through an unrestricted origin address.

Bound resource use and information exposure

AreaReview question
Request bodiesAre upload and API limits appropriate at every layer?
TimeoutsCan slow clients or stalled backends occupy workers indefinitely?
MethodsAre only the methods needed by each service accepted?
ErrorsDo responses hide stack traces, local paths and secrets?
CachingCan authenticated or private responses reach another user?
LogsAre useful events retained without credentials or sensitive payloads?

Apply rate controls to the right identity and operation where possible. A single IP limit can inconvenience shared networks and still miss abuse spread across many addresses.

Validate, deploy and verify

Run nginx -t or apachectl configtest before a reload. Keep the previous configuration and agree the rollback trigger. After deployment, test normal journeys, failures, representative uploads and the final response headers.

Use authorised requests to confirm that protected files, management routes and direct-origin paths behave as intended. Retain the configuration revision and observed results with the change record. Hardening is maintained through patching and review after deployment changes, rather than completed by one successful reload.

Further reading: Nginx documentation and Apache security tips.

Read our testing methodology or discuss your assessment.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo