Skip to content

Lesson 9 of 9 · 25m

Safe Reloads, Deployments, and Baseline Hardening

Validate configuration before applying it, understand reload semantics, and ship hardened Nginx or Apache changes without dropped requests or surprise exposure.

A reload is not a trivial ceremony. It is a deployment of the traffic control plane. The good news is that Nginx and Apache are both capable of graceful changes. The bad news is that operators routinely bypass those safeguards with forced restarts, untested includes, and configuration generated by an automation pipeline nobody can read.

Validate before reload

Always test syntax and effective configuration first:

nginx -t
systemctl reload nginx

apache2ctl configtest
systemctl reload apache2

nginx -t parses configuration and tests some file references, but it does not prove every upstream, certificate file permission, or runtime path will behave as intended. Apache configtest likewise catches syntax, not architecture. Treat successful validation as permission to proceed, not proof of correctness.

Reload semantics differ from restart

Nginx reload keeps the old master process, starts new workers, finishes in-flight work on old workers, then retires them. Apache graceful reload similarly tries to finish current requests. A full restart drops or interrupts more state and should be deliberate. If you need a new binary, changed systemd unit, kernel-level socket settings, or incompatible module changes, a reload may not be enough.

Deploy configuration like code

A sane pipeline is:

edit -> lint/configtest -> render diff -> deploy to canary -> smoke test -> broad rollout -> verify

Store the intended configuration in version control. Generate secrets or certificate references through a deployment system without placing private keys in the repository. Include rollback commands in the change ticket. If a change cannot be rolled back, it is not ready for production.

Smoke tests must exercise behavior

Do not settle for HTTP 200 on /. Test:

curl -sS -o /dev/null -w '%{http_code} %{time_total}
' https://app.sudosecurity.org/healthz
curl -sSI https://app.sudosecurity.org/static/app.css | grep -i cache-control
curl -sS -o /dev/null -w '%{http_code}
' -H 'Host: app.sudosecurity.org' https://127.0.0.1/ --resolve app.sudosecurity.org:443:127.0.0.1

Check one canonical redirect, one proxied route, one static route, one authenticated behavior where possible, and certificate correctness. Then watch error rate and latency for several minutes. Some failures only emerge as old workers drain.

Baseline hardening is mostly exposure control

server_tokens off;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always;

Hide version details where easy, but do not pretend server_tokens off is meaningful defense. Real hardening is minimizing exposed modules, controlling methods and upload sizes, protecting status and administrative endpoints, isolating file permissions, keeping TLS current, and ensuring application authorization remains server-side. Security headers help browsers enforce policy; they do not fix broken object authorization.

Apache exposure often hides in modules and .htaccess

apache2ctl -M
apache2ctl -S

List loaded modules and vhost mappings. Disable what you do not need. .htaccess can be necessary in shared hosting, but on infrastructure you control it distributes configuration across directories and adds filesystem checks. Centralize policy when possible.

Incident readiness is part of operations

Keep a clean copy of the last known good configuration, a runbook for certificate replacement, a command list for capturing evidence, and a way to put critical routes into maintenance mode. During an outage is the wrong time to learn how your distro arranges sites-enabled, conf.d, or systemd unit overrides.

Field notes

  • systemctl reload can report success while a later worker failure still disrupts traffic; watch logs after applying the change.
  • Configuration includes have ordering semantics. A file named 00- does not make the architecture correct, only earlier.
  • Do not daemon-reload or restart casually during diagnosis; you may destroy the evidence of stuck workers you needed to inspect.
  • Automate checks for certificate expiry, disk usage, file descriptors, and config drift. The common failures are boring, which is why they keep happening.

Was this lesson helpful?

Sign in to rate