BudiBadu Logo
Samplebadu
Nginx Config

Learn Nginx Config by Examples

Nginx 1.x

Nginx is a high-performance HTTP and reverse proxy server. Its configuration is known for being powerful yet concise, using a block-based syntax to define how requests are handled.

These examples cover the essential building blocks of Nginx configuration, from setting up basic server blocks and locations to advanced features like reverse proxying, SSL termination, and performance optimization.

Server Block

Defining virtual hosts with this sample code demonstrating server block configuration for domain handling, listen directive for port binding with default_server parameter, server_name for domain matching, and access/error log configuration.

Location Blocks

Routing requests based on URI patterns with this code example showing location block modifiers for exact match, prefix match, case-sensitive regex, and case-insensitive regex with priority-based selection algorithm.

Reverse Proxy

Forwarding requests to backend servers with this sample code demonstrating proxy_pass directive for upstream forwarding, proxy_set_header for client information preservation, timeout configuration, and buffer settings for response handling.

Load Balancing

Distributing traffic across multiple servers with this code example showing upstream block definition for backend server groups, load balancing methods including round-robin and least connections, server weight configuration, and health check parameters.

SSL/TLS

Securing connections with HTTPS through this sample code demonstrating SSL certificate configuration, protocol and cipher selection for security, session caching for performance, HTTP/2 enablement, and HTTP to HTTPS redirection.

Caching

Improving performance with browser and proxy caching through this code example showing expires directive for cache duration, Cache-Control header configuration, conditional caching by file type, and proxy cache setup for backend responses.

Rate Limiting

Protecting against abuse with request throttling through this sample code demonstrating limit_req_zone for defining rate limit zones, limit_req for applying limits, burst parameter for traffic spikes, and IP-based request tracking.

Compression

Reducing bandwidth usage with Gzip compression through this code example showing gzip enablement, compression level tuning, minimum file size threshold, MIME type specification, and Vary header configuration.