Skip to content

Nginx — cheat sheet

A one-page lookup for the directives used across this course. Grouped by task; the course pages cover the why behind each one — this page is just the what.

server / location — routing

Directive What it decides
listen Which port this server block answers on
server_name Which Host header value this server block answers for
location Which request path, inside a matched server block, this rule applies to
root The directory static files are served from
index The default file to serve when a request names a directory, not a file

TLS termination

Directive What it does
listen 443 ssl Opens an HTTPS listener on this server block
ssl_certificate Path to the certificate (public key) presented to the client
ssl_certificate_key Path to the matching private key
Task Mechanism
Redirect plain HTTP to HTTPS A separate server { listen 80; } block issuing return 301 https://$host$request_uri; — not a directive added to the port-443 block

Proxying & load balancing

Directive What it does
proxy_pass Forwards a matched location's requests to a single target address or an upstream name
upstream <name> { server ...; } Names a pool of servers proxy_pass http://<name>; picks from per request
Behavior Detail
Default load-balancing algorithm Round-robin, across every server named in an upstream block

nginx vs Ingress vs cloud LB

Layer Scope Who configures it
Standalone nginx One host's processes Hand-written nginx.conf server/location blocks
Kubernetes Ingress controller Services inside one cluster Ingress objects, watched and enforced by the controller
Cloud load balancer Compute across the provider's network Provider-managed resources (e.g. an ALB)

How this connects

The reverse proxy & static content page covers server/location routing, the TLS termination page covers the listen 443 ssl directives and the HTTP→HTTPS redirect, the proxying & load balancing page covers proxy_pass/upstream and round-robin, and the nginx vs Ingress & cloud LB page covers where the same job runs one layer out or one layer in.