Lesson 4 of 9 · 25m
Reverse Proxies, TLS, and Controlled Service Exposure
Terminate and route traffic deliberately, automate certificates safely, and understand which security boundary a reverse proxy does and does not provide.
A reverse proxy is often sold in home-lab forums as a magic security appliance. It is not. It is a traffic-control layer: name-based routing, TLS termination, header normalization, authentication integration, rate limiting, and sometimes a convenient place to make mistakes at scale. If every backend trusts the proxy blindly, compromising the proxy means every application suddenly believes every request is an administrator from localhost.
Decide what terminates where
There are three common termination patterns:
public edge TLS -> proxy plaintext backend simple, but internal traffic is exposed
public edge TLS -> proxy re-encrypted backend stronger, more certificate lifecycle work
end-to-end TLS with proxy as TCP passthrough least inspection, strongest backend controlFor a small lab, TLS termination at the proxy is reasonable if the service VLAN is segmented and backends only accept traffic from proxy addresses. Do not call it zero trust. It is compartmentalization with a known trusted middlebox.
Example: Caddy as the simple path
Caddy earns its popularity because correct defaults matter:
files.example.net {
reverse_proxy 10.10.30.15:8080
encode zstd gzip
header {
Strict-Transport-Security "max-age=31536000"
X-Content-Type-Options nosniff
Referrer-Policy strict-origin-when-cross-origin
}
}Automatic HTTPS is useful because expired certificates are operational vulnerabilities. They train users to click through warnings and make real attacks harder to distinguish.
Nginx gives more explicit control
server {
listen 443 ssl;
server_name files.example.net;
ssl_certificate /etc/letsencrypt/live/files.example.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/files.example.net/privkey.pem;
client_max_body_size 512m;
location / {
proxy_pass http://10.10.30.15:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}Header handling is security-critical. If the application uses X-Forwarded-For for authorization or rate limiting, accept it only from the proxy. Otherwise clients can spoof identity by sending the header directly.
ACME validation is an exposure decision
HTTP-01 requires inbound port 80 reachability. DNS-01 requires DNS API credentials. TLS-ALPN-01 requires control of 443. DNS-01 is often better for home labs behind restrictive WAN or for wildcard certificates, but a powerful DNS API token must be protected and scoped. Automate renewal and test it:
certbot renew --dry-run
systemctl list-timers | grep -E 'certbot|caddy'Authentication in front of applications
Putting SSO or forward authentication at the proxy can reduce exposure for applications with weak session controls. It does not fix broken object authorization behind the proxy. Once authenticated, a user can still exploit application flaws. Treat proxy auth as a perimeter reducer, not application security.
Service exposure checklist
Before publishing anything, answer:
What exact backend and port is exposed, and where does it bind?
Who can reach the proxy, and where does TLS terminate?
Which headers are trusted, and who can spoof them?
How are certificates renewed and monitored?
What logs prove source IP, hostname, status, and upstream latency?Field notes
- Wildcard certificates are convenient and dangerous. One stolen private key covers every hostname under the wildcard.
- Do not expose internal-only hostnames in public certificate transparency logs without thinking. Hostnames reveal system inventory.
- A proxy can centralize control, but it is also a single point of failure. Document the direct emergency path or accept that everything is down together.
- Default backend timeouts matter. Slowloris-style behavior and large uploads are often proxy resource problems before they are application problems.
Was this lesson helpful?