HomeCheat SheetsNginx Web Server & Reverse Proxy Configuration Cheat Sheet
100% Client-Side β€’ 0 B Data Leaves Browser
devops

Nginx Web Server & Reverse Proxy Configuration Cheat Sheet

Nginx configuration reference for reverse proxying, SSL/TLS certificates, WebSocket upgrades, rate limiting, and gzip compression.

Reverse Proxy & Node.js / Python Upstream

Forward HTTP requests to backend application serviceproxy_pass http://127.0.0.1:3000;
Preserve original client Host request headerproxy_set_header Host $host;
Pass original client IP address through proxy layersproxy_set_header X-Real-IP $remote_addr;
Append client IP to proxy chain headerproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Enable bidirectional WebSocket connection upgradesproxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";

Security Headers & Gzip Compression

Prevent clickjacking attacks by blocking unauthorized iframingadd_header X-Frame-Options "SAMEORIGIN" always;
Prevent MIME-type sniffing by browsersadd_header X-Content-Type-Options "nosniff" always;
Enable on-the-fly HTTP gzip compression for static assetsgzip on; gzip_types text/plain text/css application/json application/javascript text/xml;
Test nginx configuration files for syntax errors without restarting servicenginx -t
Gracefully reload configuration without dropping active connectionsnginx -s reload

Frequently Asked Questions

β€’ How do I test my Nginx config before reloading?

Always run `sudo nginx -t`. It validates the syntax of all included configuration files and reports the exact line number of any syntax error.