Lesson 1 of 9 · 24m
The Reverse Proxy Mental Model
Understand what the edge owns, what the application owns, and how Nginx or Apache changes failure behavior when it sits in front.
The worst reverse proxy outages are not caused by a bad regex or an exotic TLS setting. They happen because nobody can say which layer owns what. The proxy terminates client connections, shields slow applications, routes hostnames, enforces protocol policy, and absorbs abuse. The application still owns business logic, object authorization, and correctness. If you blur that boundary, every incident becomes a scavenger hunt.
Draw the request path first
A boring diagram prevents expensive guesses:
client -> CDN -> load balancer -> nginx/apache -> app worker -> database/cache
edge L4/L7 vhost+TLS upstream persistenceAt each hop ask: does this layer terminate, forward, transform, or store? Nginx usually terminates HTTP and proxies upstream. Apache can do the same through mod_proxy, but it also has a long history as the application server itself. The same configuration directive means different risk depending on whether the server is the edge or the origin.
A minimal Nginx reverse proxy
server {
listen 443 ssl http2;
server_name app.sudosecurity.org;
ssl_certificate /etc/nginx/tls/app.fullchain.pem;
ssl_certificate_key /etc/nginx/tls/app.key;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}Three details matter immediately. Host preserves the public hostname unless you intentionally canonicalize it. X-Forwarded-Proto tells the application whether the external connection was HTTPS. X-Forwarded-For appends the client chain; it is not trustworthy merely because the header exists.
Apache says the same thing differently
<VirtualHost *:443>
ServerName app.sudosecurity.org
SSLEngine on
SSLCertificateFile /etc/apache2/tls/app.fullchain.pem
SSLCertificateKeyFile /etc/apache2/tls/app.key
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>ProxyPassReverse rewrites redirects and location headers coming back from the application. Without it, an app redirect to http://127.0.0.1:8080/login leaks internal topology and breaks the client journey.
Timeouts define behavior under stress
A reverse proxy is a queue manager. If upstreams hang, your workers hang. Defaults are often too generous for a failing application:
proxy_connect_timeout 5s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;Short connection timeouts fail fast when the upstream is dead. Read timeouts need care: long-polling, server-sent events, uploads, and report generation are not ordinary requests. Route them separately instead of loosening every timeout globally.
Field notes
- Trailing slashes in
proxy_passare semantic, not cosmetic; they change whether the location prefix is replaced. 127.0.0.1on one machine becomes a network hop in containers and service meshes; draw the real path.- Do not let the application trust
X-Forwarded-*from direct traffic unless only the proxy can reach it. - If a request works through the proxy but fails direct-to-app, congratulations: you found the difference. Now identify whether headers, host, protocol, or buffering caused it.
Was this lesson helpful?