ToolSnippet
⚙️Developer Cheat Sheet

Nginx Server Block Directives, Location Matching & Proxy Reference

Developer cheat sheet for Nginx location block matching order, reverse proxy headers, WebSocket upgrades, SSL hardening, and gzip compression.

1-Click Syntax CopyProduction-Tested StandardsInteractive Tool Companion

Need to generate an Nginx virtual host configuration?

Build complete reverse proxy configs with SSL, gzip, security headers, and WebSocket support.

Launch Nginx Virtual Host Config Builder

Location Block Modifiers & Match Priority

Order of evaluation Nginx uses to select matching location blocks.

Syntax / TokenName / TypeDescriptionExample / Notes
location = /exact/path
1. Exact Match (=)Highest priority. Matches only exact URI string. Processing stops immediately upon match.
location ^~ /images/
2. Preferential Prefix (^~)Matches prefix URI. If matched, Nginx skips regular expression checking.
location ~ \.php$
3. Case-Sensitive RegEx (~)Evaluated in order of appearance in configuration file.
location ~* \.(jpg|png)$
4. Case-Insensitive RegEx (~*)Evaluates regex without case sensitivity.
location /prefix/
5. Standard Prefix (None)Longest matching prefix is used if no regex matches.

Standard Reverse Proxy Directives

Essential proxy headers for Node.js, Python, and Go backends.

Syntax / TokenName / TypeDescriptionExample / Notes
proxy_pass http://127.0.0.1:3000;
Upstream TargetPasses request to specified backend application server
proxy_set_header Host $host;
Host HeaderForwards the original request Host header to backend
proxy_set_header X-Real-IP $remote_addr;
Client IP HeaderForwards the actual visitor IP address
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Forwarded ForAppends client IP to proxy chain list
proxy_set_header X-Forwarded-Proto $scheme;
Protocol HeaderInforms backend whether client connected over http or https

SPA & Static Asset Fallbacks

Clean URL routing for React, Vue, Next.js, and static sites.

Syntax / TokenName / TypeDescriptionExample / Notes
try_files $uri $uri/ /index.html;
SPA History FallbackServes file, directory, or falls back to index.html for client-side routing
expires 1y; add_header Cache-Control "public, immutable";
Static Asset CachingLong-term caching for hashed JS/CSS/image assets

Frequently Asked Questions

Common questions and developer tips regarding nginx location directives & reverse proxy guide.

Explore More Cheat Sheets

All Cheat Sheets →