Skip to main content
Cloud & DevOps

Nginx Web Server & Reverse Proxy

Essential

Production Nginx reverse proxy directives, SSL/TLS termination, rate limiting, gzip compression, and upstream load balancing.

Instant Copy & SearchProduction Flagged SyntaxCurrent Flag Reference

Nginx Web Server & Reverse Proxy Interactive Command Directory

Browse, search, and copy battle-tested commands & syntax recipes (14 Total Commands).

14+ Verified Recipes
CLI Management-t
nginx -t

Test Nginx configuration files for syntax errors and valid directives.

CLI Management-s reload
nginx -s reload

Gracefully reload Nginx configuration without terminating existing active client connections.

Reverse Proxyproxy_pass
location /api/ { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }

Forward incoming requests to backend API server while preserving client IP headers.

Rate Limitinglimit_req_zone
limit_req_zone $binary_remote_addr zone=ip_limit:10m rate=10r/s;

Define shared memory zone allocating 10MB to track IP requests and enforce 10 req/sec limit.

Security Headersadd_header
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

Enforce HTTP Strict Transport Security (HSTS) on all client responses.

SSL/TLS Directivesssl_protocols
ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5;

Restrict encryption to secure modern TLS protocols and disable legacy weak ciphers.

Gzip Compressiongzip, gzip_types
gzip on; gzip_min_length 1024; gzip_types text/plain application/json text/css application/javascript;

Enable automatic gzip payload compression on text and JSON responses exceeding 1KB.

Load Balancingupstream
upstream backend_pool { ip_hash; server app1.internal:8080; server app2.internal:8080 max_fails=3; }

Define upstream load balancer with session affinity (ip_hash) and health failure thresholds.

Static Assetsexpires, Cache-Control
location ~* \.(jpg|png|webp|css|js)$ { expires 30d; add_header Cache-Control "public, immutable"; }

Set aggressive 30-day client-side caching headers for static media files.

Reverse Proxy Blockproxy_pass
location /api/ { proxy_pass http://127.0.0.1:8000/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }

Standard production reverse proxy configuration forwarding traffic to backend microservices with client IP headers.

WebSocket UpgradeUpgrade / Connection
location /ws/ { proxy_pass http://127.0.0.1:3001; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }

Configure HTTP hop-by-hop headers to support bi-directional WebSocket full-duplex communication streams.

Rate Limitinglimit_req_zone
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s; location /login/ { limit_req zone=api_limit burst=20 nodelay; }

Mitigate brute-force attacks and volumetric DDoS using leaky-bucket IP rate limiting with burst buffers.

Gzip Compressiongzip on
gzip on; gzip_comp_level 5; gzip_min_length 256; gzip_types text/plain text/css application/json application/javascript text/xml application/xml+rss image/svg+xml;

Compress text-based HTTP responses using gzip to cut bandwidth consumption and improve Core Web Vitals.

SSL / TLS 1.3 Hardeningssl_protocols
ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256; ssl_prefer_server_ciphers off; ssl_session_cache shared:SSL:10m; ssl_session_timeout 1d;

Modern SSL security profile enforcing TLS 1.2/1.3 and forward-secret ciphers for A+ Qualys SSL ratings.

Zero Setup100% In-Browser Execution

Companion Developer Tools & Playgrounds

Accelerate command execution and syntax debugging with HelloAIHub suite of interactive tools.

Explore all developer tools

Nginx Web Server & Reverse Proxy: Command Groups & Quick Index

14 indexed entries across 11 sections
CLI Management2 items
Reverse Proxy1 items
Rate Limiting2 items
Security Headers1 items
SSL/TLS Directives1 items
Gzip Compression2 items
Load Balancing1 items
Static Assets1 items
Reverse Proxy Block1 items
WebSocket Upgrade1 items
SSL / TLS 1.3 Hardening1 items

Highlighted Flags & Syntax Examples in Nginx Web Server & Reverse Proxy

nginx -t

Test Nginx configuration files for syntax errors and valid directives.

Flags: -t
nginx -s reload

Gracefully reload Nginx configuration without terminating existing active client connections.

Flags: -s reload
location /api/ { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }

Forward incoming requests to backend API server while preserving client IP headers.

Flags: proxy_pass
limit_req_zone $binary_remote_addr zone=ip_limit:10m rate=10r/s;

Define shared memory zone allocating 10MB to track IP requests and enforce 10 req/sec limit.

Flags: limit_req_zone

Frequently Asked Questions

Expert recommendations, common traps, and production best practices for Nginx Web Server & Reverse Proxy.

What is the difference between proxy_pass with and without a trailing slash?

With a trailing slash (e.g., proxy_pass http://backend/;), Nginx strips the matching location URI prefix before forwarding. Without a trailing slash (proxy_pass http://backend;), the full raw URI requested by the client is passed unchanged.

How does Nginx handle worker processes and connections?

Nginx uses an asynchronous, non-blocking event-driven loop. Setting 'worker_processes auto;' matches the number of CPU cores, while 'worker_connections 1024;' allows each worker to multiplex thousands of concurrent client connections simultaneously.

What is the difference between Nginx reload and restart?

nginx restart terminates the running master process and worker threads completely, dropping all active TCP connections during startup. nginx -s reload tells the master process to spawn new worker processes with the updated config while allowing existing workers to complete in-flight client requests, achieving true zero-downtime reconfiguration.

Why does Nginx outperform Apache in high-concurrency environments?

Apache traditionally used process-driven or thread-driven architectures (spawning an OS thread per connection, leading to heavy context switching). Nginx uses an asynchronous, non-blocking event-driven architecture based on epoll/kqueue where a single worker process handles tens of thousands of concurrent connections on minimal RAM.

What is the trailing slash pitfall in Nginx proxy_pass?

If you define proxy_pass http://backend/; (with a trailing slash), Nginx strips the matched location prefix before forwarding. If defined as proxy_pass http://backend; (without a trailing slash), Nginx appends the full URI path. Misunderstanding this causes unexpected 404 routing errors.

How can I configure Nginx as a load balancer across multiple backend servers?

Define an upstream block: upstream backend_nodes { server 10.0.0.1:8080 weight=3; server 10.0.0.2:8080; } and reference it via proxy_pass http://backend_nodes;. Nginx distributes requests using round-robin, least_conn, or ip_hash algorithms.

Cross-Hub Skill Acceleration

Combine command lookups with active coding interviews and complete career paths.

Need More Cheat Sheets?

Explore developer cheat sheets and syntax guides on HelloAIHub.

Browse All Cheat Sheets