Cheatsheet: Nginx
Last updated 2026-09-29
Config File Structure
Minimal server block structure
Default config file locations
Include additional config files
Location Block Matching
Exact match (highest precedence)
Prefix match that skips regex checking
Case-sensitive / case-insensitive regex match
Plain prefix match (longest wins, checked last)
Named location (only reachable via internal redirect, e.g. error_page/try_files)
Reverse Proxy & Load Balancing
Proxy requests to an upstream server
Preserve the original Host header and client IP
Define an upstream group of servers
Load-balance by least active connections
Sticky sessions by client IP
Mark a server as backup (only used if others are down)
TLS / SSL
Listen for HTTPS and specify certificate/key
Redirect all HTTP traffic to HTTPS
Restrict to modern TLS versions
Test the config after certificate changes, then reload
Gzip Compression
Enable gzip and list the MIME types to compress
Only compress responses above a minimum size
Compress responses even when Nginx is proxying them
CLI & Process Management
Test config syntax without applying it
Reload config gracefully (no dropped connections)
Stop immediately (fast shutdown, drops connections)
Quit gracefully (finishes in-flight requests)
Show version and compiled-in modules
Tail the default access/error logs