52 SECTIONS · 1515 TOPICS
Nginx Roadmap
Installing and Compiling Nginx
- 1. Installing from Package Managers
- Example: Verify Installation
- 2. Installing from Official Repository
- Example: Add Nginx Repo on Ubuntu
- 3. Compiling from Source
- Example: Configure with Custom Modules
- 4. Adding Custom Modules
- Example: Add OpenResty Module
- 5. Verifying Installation
- Example: Test Configuration
- 6. Understanding Build Configuration
- Example: Full Build Configuration
- 7. Installing Dynamic Modules
- Example: Enable Dynamic Module
- 8. Setting Up Service Management
- Example: Start Nginx Service
- 9. Configuring Auto-start
- Example: Enable Auto-start on Boot
- 10. Installing on Docker
- Example: Run Nginx in Docker
- 11. Installing on Alpine Linux
- Example: Install Nginx on Alpine
- 12. Upgrading Nginx Binary
- Example: Upgrade via Package Manager
Managing Nginx Service
- 1. Starting Nginx
- Example: Starting Nginx service
- 2. Stopping Nginx
- Example: Stopping Nginx via systemctl
- 3. Reloading Configuration
- Example: Reloading Nginx Configuration
- 4. Testing Configuration
- Example: Test Nginx Configuration
- 5. Checking Service Status
- Example: Check Nginx service status
- Example: Test Nginx configuration
- 6. Viewing Running Processes
- Example: Check Nginx Process Status
- 7. Sending Signals
- Example: Reload Nginx Configuration
- 8. Performing Graceful Shutdown
- Example: Graceful shutdown using signal
- Shutdown Process Overview
- 9. Reopening Log Files
- Example: Reopening Log Files
- 10. Understanding Master and Worker Processes
- Example: Master and Worker Process Configuration
- Key Points About Nginx Processes
- 11. Upgrading Without Downtime
- Upgrade Process
- Example: Performing a Zero-Downtime Reload
- 12. Managing Multiple Nginx Instances
- Example: Running Multiple Nginx Instances with Different Configs
Working with Configuration Structure
- 1. Understanding Main Context
- 2. Locating Configuration Files
- Example: Default nginx.conf location
- 3. Using Include Directive
- Example: Including a Server Block Configuration
- 4. Organizing Configuration Files
- Example: Main nginx.conf structure
- Configuration Organization Best Practices
- Steps to Organize Configuration Files
- 5. Setting Global Directives
- Example: Setting Global Directives
- 6. Configuring Events Block
- Example: Basic Events Block Configuration
- 7. Understanding Configuration Hierarchy
- Example: Configuration Hierarchy
- 8. Using Configuration Variables
- Example: Defining and Using Variables
- Example: Using Variables in Conditions
- 9. Commenting Configuration
- Example: Using Comments in Nginx Config
- 10. Splitting Configuration into Modules
- Example: Including a Module
- Example: Server Configuration Module
- 11. Validating Configuration Syntax
- Example: Basic syntax validation
- Example: Test with specific config file
- 12. Understanding Directive Inheritance
- Example: Inheritance in Action
- Key Points
Configuring HTTP Block
- 1. Setting MIME Types
- Example: Custom MIME Type
- 2. Configuring Access Logging
- Example: Basic Access Log Configuration
- Example: Custom Log Format
- Example: Using JSON Format for Logs
- 3. Configuring Error Logging
- Example: Basic Error Logging Configuration
- Example: Logging to Standard Error
- Example: Disabling Error Logging
- 4. Setting Charset
- Example: Setting Default Charset
- 5. Configuring Keepalive
- Example: Basic Keepalive Configuration
- 6. Setting Client Body Size
- Example: Setting client_max_body_size
- Example: Setting client_body_buffer_size
- 7. Configuring Buffer Sizes
- Example: Setting buffer sizes for large uploads
- 8. Setting Timeouts
- Example: Timeout Configuration
- 9. Configuring TCP Options
- Example: Enabling TCP optimizations
- 10. Setting Server Tokens
- Example: Disabling Server Tokens
- 11. Configuring Default Server
- Example: Default Server Configuration
- 12. Setting Real IP
- Example: Basic real IP configuration
Creating Server Blocks
- 1. Defining Server Block
- Example: Basic Server Block Configuration
- 2. Configuring Listen Directive
- Example: Basic HTTP server block with listen directive
- Example: HTTPS server block with SSL listen directive
- 3. Setting Server Name
- Example: Basic server_name configuration
- 4. Using Wildcard Server Names
- Example: Wildcard server name configuration
- 5. Setting Default Server
- Example: Default Server Configuration
- 6. Configuring Multiple Server Blocks
- Example: Basic Multiple Server Blocks Setup
- Workflow: Enabling Multiple Server Blocks
- 7. Setting Root Directory
- Example: Setting Root Directory
- 8. Configuring Index Files
- Example: Setting Index Files
- 9. Using Server Name Matching
- Example: Basic server_name usage
- Example: Regex server_name
- 10. Setting Server-specific Variables
- Example: Setting Custom Variables
- 11. Understanding Server Block Selection
- Example: Matching server_name directive
- 12. Implementing Catch-all Server Block
- Example: Catch-all server block returning 444
Working with Location Blocks
- 1. Defining Location Block
- Example: Basic Location Block
- Example: Exact Match Location Block
- 2. Understanding Location Matching
- Example: Location Priority
- 3. Using Exact Match
- Example: Exact Match Location Block
- 4. Using Prefix Match
- Example: Prefix Match Configuration
- 5. Using Regex Match
- Example: Case-sensitive regex match
- Example: Case-insensitive regex match
- 6. Using Case-Insensitive Regex
- Example: Case-Insensitive Location Match
- 7. Understanding Location Priority
- Example: Location Priority in Action
- 8. Using Preferential Prefix
- Example: Preferential Prefix Usage
- 9. Nesting Location Blocks
- Example: Nested Location Blocks
- Matching Priority
- 10. Setting Location-specific Directives
- Example: Using alias and root
- Example: Using try_files for fallback handling
- 11. Using Named Locations
- Example: Redirect to Named Location
- 12. Redirecting to Named Location
- Example: Redirecting to Named Location
Using Nginx Variables
- 1. Understanding Built-in Variables
- Example: Using Variables in Location Blocks
- 2. Using Request Variables
- Example: Using Variables in Location Block
- Example: Logging Request Variables
- 3. Using Client Variables
- Example: Logging Client IP Address
- Example: Blocking Requests Based on User Agent
- 4. Using Server Variables
- Example: Logging Server Name
- 5. Using Upstream Variables
- Example: Logging Upstream Variables
- 6. Using SSL Variables
- Example: Logging SSL Variables
- Example: Redirecting Based on SSL Protocol
- 7. Using Time Variables
- Example: Logging with Time Variables
- 8. Creating Custom Variables
- Example: Setting a Custom Variable
- Example: Using Variables in Headers
- 9. Using Map Directive
- Example: Basic Map Usage
- Map Directive Summary
- 10. Using Geo Directive
- Example: Using geo with country code
- 11. Understanding Variable Evaluation
- Example: Using Variables in Location Blocks
- 12. Using Regex Captures in Variables
- Example: Capturing and Using URI Components
- Key Points
Serving Static Content
- 1. Configuring Root Directory
- Example: Setting Root Directory
- 2. Using Alias Directive
- Example: Serving Images with Alias
- 3. Setting Index Files
- Example: Basic Index File Configuration
- 4. Enabling Directory Listing
- Example: Enabling Directory Listing
- 5. Customizing Autoindex
- Example: Enabling and Customizing Autoindex
- 6. Setting File Permissions
- Example: Setting File Permissions
- 7. Configuring Expires Headers
- Example: Setting Expires Headers for Static Assets
- Example: Using expires_by_type for Different Media Types
- 8. Adding Cache-Control Headers
- Example: Setting Cache-Control for Static Assets
- Example: Using expires with relative time
- 9. Serving Files with Try Files
- Example: Basic try_files usage
- Example: Fallback to 404
- 10. Handling Missing Files
- Example: 404 Error Page
- Example: Fallback to Index
- 11. Serving Pre-compressed Files
- Example: Serving pre-compressed files
- 12. Implementing Byte-Range Requests
- Example: Enabling Range Requests
Implementing Rewrite Rules
- 1. Using Rewrite Directive
- Example: Basic Rewrite Rule
- Example: Rewrite with Capture Groups
- 2. Understanding Rewrite Flags
- Example: Using
- Example: Using
- 3. Using Return Directive
- Example: Simple 404 Response
- Example: Permanent Redirect
- 4. Implementing 301 Redirects
- Example: Basic 301 Redirect
- Example: Redirect with Capture Group
- 5. Implementing 302 Redirects
- Example: Basic 302 Redirect
- Example: Redirect with Regex Capture
- 6. Creating Conditional Rewrites
- Example: Conditional Redirect Based on User Agent
- Example: Conditional Rewriting Based on IP Address
- 7. Using Regex Captures
- Example: Capturing and Redirecting
- 8. Rewriting with Query String
- Example: Rewrite with Query String
- 9. Testing Conditions
- Example: Testing file existence
- Example: Testing directory existence
- Example: Testing file size
- Example: Testing file permissions
- Example: Testing symbolic links
- Example: Testing file type
- Example: Testing directory type
- Example: Testing file ownership
- Example: Testing file executable permissions
- Example: Testing file writable permissions
- Example: Testing file readable permissions
- Example: Testing file zero-length
- Example: Testing file not readable
- Example: Testing file not writable
- Example: Testing file not executable
- Example: Testing file not owned by current user
- Example: Testing file not a regular file
- Example: Testing file not a directory
- Example: Testing file not a socket
- Example: Testing file not a pipe or FIFO
- 10. Preserving Query Strings
- Example: Rewrite with Query String Preservation
- 11. Using Rewrite Log
- Example: Enabling Rewrite Logging
- 12. Understanding Rewrite vs Return
- Example: Using
- Example: Using
- Comparison:
Working with Headers
- 1. Adding Custom Headers
- Example: Adding a Custom Header
- 2. Removing Headers
- 3. Setting Response Headers
- Example: Adding a Custom Header
- Example: Setting Cache Control
- 4. Using Always Parameter
- Example: Using
- Example: Using
- 5. Configuring CORS Headers
- Example: Basic CORS Configuration
- Example: CORS with Credentials
- 6. Setting Security Headers
- Example: Setting Security Headers in Nginx
- 7. Adding Content Security Policy
- Example: Setting CSP Header
- Example: CSP Report Only Mode
- 8. Setting Referrer Policy
- Example: Setting Referrer Policy
- 9. Configuring Permissions Policy
- Example: Setting Permissions Policy
- 10. Using Header Variables
- Example: Setting a Custom Header Based on a Query Parameter
- Example: Using a Request Header to Modify Response
- 11. Proxying Request Headers
- Example: Setting Forwarded Headers
- 12. Understanding Header Inheritance
Handling Error Pages
- 1. Configuring Error Pages
- Example: Basic Error Page Configuration
- Example: Custom Redirect for 404 Errors
- 2. Setting Custom Error Pages
- Example: Custom 404 Page
- Example: Multiple Error Pages
- 3. Using Internal Redirects
- Example: Internal Redirect for 404 Errors
- 4. Handling Multiple Error Codes
- Example: Custom Error Page Configuration
- 5. Setting Error Page Response Code
- Example: Custom 404 Page with Redirect
- Example: Change 500 Error Code to 200
- 6. Using Named Locations for Errors
- Example: Using Named Locations for Error Handling
- 7. Proxying Error Pages
- Example: Basic Error Page Proxying
- Example: Proxying to Upstream Server
- 8. Configuring Recursive Error Pages
- Example: Basic Recursive Error Page Configuration
- Example: Recursive Error Handling with Custom Logic
- 9. Setting Default Error Responses
- Example: Basic 404 Error Page
- Example: Multiple Error Pages
- 10. Logging Error Details
- Example: Configuring Error Logging
- Example: Log Level Configuration
- Error Log Levels
- 11. Implementing Custom Error Templates
- Example: Basic custom error page setup
- Example: Custom 404 page with dynamic content
- Example: Using variables in error pages
- 12. Handling Upstream Errors
- Example: Custom Error Page for 502 Errors
- Example: Default Error Page for All Errors
Implementing Reverse Proxy
- 1. Configuring Proxy Pass
- Example: Basic proxy_pass configuration
- Example: Proxying to Unix socket
- 2. Setting Proxy Headers
- Example: Configuring Proxy Headers
- 3. Forwarding Client IP
- Example: Configuring IP forwarding
- 4. Preserving Host Header
- Example: Setting Host Header
- 5. Configuring Proxy Buffering
- Example: Enabling proxy buffering
- 6. Setting Proxy Timeouts
- Example: Configuring Proxy Timeouts
- 7. Handling Proxy Redirects
- Example: Basic proxy_redirect usage
- Example: Using proxy_redirect with regex
- 8. Configuring WebSocket Proxying
- Example: Basic WebSocket Configuration
- 9. Using Upstream Variables
- Example: Using upstream variables in logs
- 10. Setting Proxy SSL
- Example: Basic SSL proxy configuration
- Example: Mutual TLS proxy configuration
- 11. Configuring Proxy Cache Key
- Example: Custom Cache Key
- 12. Understanding Proxy Buffer Sizes
- Example: Configuring proxy buffering
Configuring Load Balancing
- 1. Defining Upstream Block
- Example: Basic upstream block
- Example: Upstream with weight and failover
- 2. Adding Backend Servers
- Example: Basic Upstream Configuration
- Example: Upstream with Weighted Servers
- 3. Using Round Robin
- Example: Round Robin Load Balancing Configuration
- 4. Configuring Least Connections
- Example: Least Connections Configuration
- 5. Using IP Hash
- Example: Basic IP Hash Configuration
- 6. Implementing Hash Method
- Example: Using ip_hash for session persistence
- Example: Using hash with custom variable
- 7. Setting Server Weights
- Example: Configuring server weights in an upstream block
- 8. Marking Servers as Backup
- Example: Backup Server Configuration
- 9. Setting Server as Down
- Example: Marking a server as down in an upstream block
- 10. Configuring Max Fails
- Example: Configuring max_fails and fail_timeout
- 11. Enabling Slow Start
- Example: Configuring Slow Start for a Backend Server
- 12. Using Keepalive Connections
- Example: Configuring Keepalive in Nginx
Implementing Health Checks
- 1. Configuring Passive Health Checks
- Example: Basic Passive Health Check Configuration
- Example: Custom URI and Method
- 2. Setting Fail Timeout
- Example: Configuring proxy_next_upstream_timeout
- 3. Using Active Health Checks
- Example: Basic Active Health Check Configuration
- 4. Configuring Health Check Interval
- Example: Setting Health Check Interval
- 5. Setting Health Check URI
- Example: Basic Health Check URI Configuration
- Example: Custom Health Check URI with Parameters
- 6. Using Match Block for Conditions
- Example: Match block for URI pattern
- Example: Match block with method and header
- 7. Configuring Health Check Port
- Example: Configuring Health Check Port
- 8. Understanding Health Check States
- Example: Health Check Configuration
- 9. Monitoring Upstream Health Status
- Example: Basic Health Check Configuration
- Example: Advanced Health Check with Custom Parameters
- 10. Implementing Custom Health Endpoints
- Example: Basic Health Check Endpoint
- Example: Health Check with Status File
- 11. Configuring Health Check Passes
- Example: Basic Health Check Configuration
- Example: Custom Health Check Passes
- 12. Using Mandatory Health Checks
- Example: Basic Health Check Configuration
- Example: Advanced Health Check with Custom URI and Timeout
Configuring FastCGI (PHP)
- 1. Setting FastCGI Pass
- Example: Basic FastCGI Pass Configuration
- 2. Configuring FastCGI Params
- Example: Setting FastCGI Parameters
- 3. Including FastCGI Config
- Example: Including FastCGI Config
- 4. Setting Script Filename
- Example: Setting SCRIPT_FILENAME
- 5. Configuring PHP-FPM
- Example: Basic PHP-FPM Configuration
- Example: PHP-FPM with TCP Socket
- 6. Setting FastCGI Index
- Example: Setting FastCGI Index
- 7. Configuring FastCGI Buffering
- Example: Enabling FastCGI Buffering
- 8. Setting FastCGI Timeouts
- Example: Setting FastCGI Timeouts
- 9. Using FastCGI Cache
- Example: Basic FastCGI Cache Setup
- Example: Cache Path Configuration
- 10. Splitting Path Info
- Example: Setting up path info splitting
- 11. Setting FastCGI Buffer Sizes
- Example: Configuring FastCGI Buffer Sizes
- 12. Configuring FastCGI Intercept Errors
- Example: Enabling FastCGI Error Interception
Implementing uWSGI Support (Python)
- 1. Setting uWSGI Pass
- Example: Basic uWSGI Pass Configuration
- 2. Configuring uWSGI Params
- Example: Basic uWSGI Configuration
- 3. Including uWSGI Config
- Example: Basic uWSGI Configuration
- 4. Using Unix Socket
- Example: Nginx configuration with Unix socket
- 5. Setting uWSGI Timeouts
- Example: Configuring uWSGI Timeouts
- 6. Configuring uWSGI Buffering
- Example: Enabling uWSGI Post Buffering
- 7. Using uWSGI Cache
- Example: Basic uWSGI Cache Configuration
- 8. Setting uWSGI Buffer Sizes
- Example: Configuring uWSGI Buffer Settings
- 9. Handling uWSGI Errors
- Example: Error Log Configuration
- Example: uWSGI Log Configuration
- 10. Configuring uWSGI for Django
- Example: Basic uWSGI Configuration for Django
- 11. Configuring uWSGI for Flask
- Example: Basic uWSGI Configuration for Flask App
- 12. Implementing uWSGI Cache Zones
- Example: Basic uWSGI Cache Configuration
- Example: Advanced uWSGI Cache with Locking
Implementing SCGI Support
- 1. Setting SCGI Pass
- Example: Basic SCGI Pass Configuration
- Example: SCGI Pass with Unix Socket
- 2. Configuring SCGI Params
- Example: Basic SCGI Configuration
- 3. Including SCGI Config
- Example: Basic SCGI Configuration
- 4. Using TCP Socket
- Example: Basic SCGI Configuration with TCP Socket
- 5. Setting SCGI Timeouts
- Example: Configuring SCGI Timeouts
- 6. Configuring SCGI Buffering
- Example: SCGI Buffering Configuration
- 7. Setting SCGI Buffer Sizes
- Example: Configuring SCGI Buffer Sizes
- 8. Handling SCGI Errors
- Example: Error Page Configuration
Implementing WebSocket Support
- 1. Configuring Proxy for WebSocket
- Example: Basic WebSocket proxy configuration
- 2. Setting Upgrade Header
- Example: Configuring WebSocket Upgrade Headers
- 3. Setting Connection Header
- Example: Configuring WebSocket Headers
- 4. Using Map for Connection
- Example: Setting up a map for WebSocket connections
- 5. Setting WebSocket Timeouts
- Example: Configuring WebSocket timeouts
- 6. Configuring WebSocket with SSL
- Example: Basic WebSocket over SSL Configuration
- 7. Load Balancing WebSockets
- Example: Basic WebSocket Load Balancing Configuration
- Load Balancing Strategies for WebSockets
- 8. Handling WebSocket Keepalive
- Example: Configuring WebSocket Keepalive
- 9. Debugging WebSocket Connections
- Example: Basic WebSocket Proxy Configuration
- Common Debugging Steps
- 10. Using WebSocket with Subprotocols
- Example: Configuring WebSocket with Subprotocols
- 11. Implementing WebSocket Ping/Pong
- Example: Basic WebSocket Configuration with Ping/Pong
- 12. Handling WebSocket Disconnections
- Example: Basic WebSocket Configuration with Timeout Handling
Implementing SSL/TLS
- 1. Enabling SSL
- Example: Basic SSL Configuration
- 2. Configuring SSL Certificate
- Example: Basic SSL Configuration
- 3. Setting SSL Private Key
- Example: Basic SSL Configuration
- 4. Configuring SSL Protocols
- Example: Enabling TLS 1.2 and 1.3
- 5. Setting SSL Ciphers
- Example: Configuring SSL Ciphers
- 6. Preferring Server Ciphers
- Example: Setting Preferred Ciphers in Nginx
- 7. Enabling SSL Session Cache
- Example: Configuring SSL Session Cache
- 8. Setting Session Timeout
- Example: Configuring SSL Session Timeout
- 9. Using OCSP Stapling
- Example: Enabling OCSP Stapling
- 10. Configuring HSTS
- Example: Basic HSTS Configuration
- Example: HSTS with Preload
- 11. Redirecting HTTP to HTTPS
- Example: Basic HTTP to HTTPS Redirect
- 12. Using SSL with SNI
- Example: Basic SNI Configuration
Working with Let's Encrypt
- 1. Installing Certbot
- Example: Install Certbot on Ubuntu
- 2. Generating Certificates
- Example: Requesting a certificate using certbot
- Summary of Certificate Generation Steps
- 3. Using Webroot Authentication
- Example: Webroot Authentication Setup
- 4. Using Standalone Mode
- Example: Issuing a certificate in standalone mode
- 5. Configuring Auto-renewal
- Example: Setting up Auto-Renewal with Certbot
- Auto-Renewal Best Practices
- 6. Setting Renewal Hooks
- Example: Renewal Hook for Nginx Reload
- 7. Managing Multiple Domains
- Example: Nginx Configuration for Multiple Domains
- Workflow: Adding New Domain to Let's Encrypt
- Summary: Multiple Domains with Let's Encrypt
- 8. Using DNS Challenge
- Example: DNS Challenge Configuration
- 9. Configuring Certificate Paths
- Example: Basic SSL Configuration
- 10. Testing Certificate Renewal
- Example: Simulate renewal with certbot
- Testing Renewal Process
- 11. Using Wildcard Certificates
- Example: Requesting Wildcard Certificate
- 12. Revoking Certificates
- Example: Revoking a Certificate
Implementing Advanced SSL
- 1. Configuring Client Certificates
- Example: Basic Client Certificate Configuration
- 2. Verifying Client Certificates
- Example: Enabling Client Certificate Verification
- 3. Extracting Client Certificate Info
- Example: Configuring Client Certificate Verification
- 4. Using Certificate Chain
- Example: Configuring SSL with Certificate Chain
- 5. Implementing OCSP Must-Staple
- Example: Basic OCSP Stapling Configuration
- 6. Configuring SSL Session Tickets
- Example: Enabling SSL Session Tickets
- 7. Using ECDH Curves
- Example: Configuring ECDH Curves in Nginx
- 8. Implementing Certificate Pinning
- Example: Enabling OCSP Stapling
- 9. Configuring Early Data
- Example: Enabling Early Data
- 10. Implementing Encrypted Client Hello
- Example: Enabling ECH in Nginx
- 11. Using Multiple SSL Certificates
- Example: Configuring Multiple Certificates
- 12. Monitoring SSL Certificate Expiry
- Example: Setting up SSL with OCSP Stapling
- Monitoring Certificate Expiry
Implementing HTTP/2
- 1. Enabling HTTP/2
- Example: Basic HTTP/2 Configuration
- 2. Configuring HTTP/2 Push
- Example: Enabling HTTP/2 Push
- 3. Setting HTTP/2 Max Streams
- Example: Configuring HTTP/2 Max Streams
- 4. Configuring HTTP/2 Body Preread
- Example: Setting HTTP/2 Body Preread Size
- 5. Setting HTTP/2 Timeouts
- Example: Configuring HTTP/2 Timeouts
- 6. Optimizing HTTP/2 Performance
- Example: Configuring HTTP/2 Performance Settings
- Performance Tuning Tips
- 7. Understanding HTTP/2 vs HTTP/1.1
- Example: Enabling HTTP/2 in Nginx
- Key Benefits of HTTP/2
- HTTP/1.1 vs HTTP/2
- 8. Implementing Server Push Preload
- Example: Enabling Server Push Preload
- 9. Configuring HTTP/2 Idle Timeout
- Example: Setting HTTP/2 Idle Timeout
- 10. Setting HTTP/2 Max Requests
- Example: Configuring max requests
- 11. Using HTTP/2 with Proxied Backends
- Example: Basic HTTP/2 Proxy Configuration
- 12. Debugging HTTP/2 Connections
- Example: Using curl with HTTP/2
Implementing HTTP/3 and QUIC
- 1. Enabling HTTP/3
- Example: Enabling HTTP/3 in Nginx
- 2. Setting QUIC Parameters
- Example: Configuring QUIC Parameters
- 3. Configuring Alt-Svc Header
- Example: Setting Alt-Svc Header
- 4. Understanding QUIC vs TCP
- QUIC vs TCP: Key Differences
- Example: Enabling HTTP/3 in Nginx
- 5. Configuring QUIC Active Connection
- Example: Enabling QUIC Active Connection
- 6. Setting QUIC Retry
- Example: Enabling QUIC Retry
- 7. Configuring QUIC GSO
- Example: Enabling QUIC GSO
- 8. Using 0-RTT with QUIC
- Example: Enabling 0-RTT with QUIC
- 9. Debugging QUIC Connections
- Example: Enabling QUIC Debug Logs
- Debugging Workflow
- QUIC vs TCP Debugging
- 10. Understanding HTTP/3 Limitations
- 11. Implementing HTTP/3 Fallback
- Example: Basic HTTP/3 Configuration with Fallback
- 12. Monitoring HTTP/3 Performance
- Example: Enabling HTTP/3 Performance Metrics in Nginx
- Key Metrics to Track
Configuring Proxy Cache
- 1. Setting Up Proxy Cache Path
- Example: Basic proxy_cache_path configuration
- Key Parameters
- 2. Enabling Proxy Cache
- Example: Basic Proxy Cache Configuration
- 3. Setting Cache Validity
- Example: Setting cache validity for different response codes
- 4. Configuring Cache Key
- Example: Custom Cache Key
- 5. Bypassing Cache
- Example: Bypass cache based on user agent
- 6. Setting No Cache Conditions
- Example: proxy_no_cache with multiple conditions
- 7. Using Cache Lock
- Example: Enabling Cache Lock
- 8. Setting Cache Methods
- Example: Enabling Cache for POST Requests
- 9. Adding Cache Status Header
- Example: Adding Cache Status Header
- 10. Purging Cache
- Example: Purging Cache by URL
- Example: Purging Cache with Specific Key
- Key Points
- 11. Configuring Cache Revalidation
- Example: Configuring Cache Revalidation
- 12. Setting Cache Background Update
- Example: Enabling Background Update
Implementing Microcaching
- 1. Setting Short Cache Times
- Example: Setting cache validity to 1 minute
- Example: Setting cache validity for different response types
- 2. Caching Dynamic Content
- Example: Basic Dynamic Content Caching
- Example: Caching with Stale Content Fallback
- 3. Using Cache Bypass for Logged-in Users
- Example: Bypass cache for logged-in users
- Example: Using a variable to control cache bypass
- 4. Configuring Stale Cache
- Example: Stale Cache Configuration
- 5. Setting Cache Lock Timeout
- Example: Configuring Cache Lock Timeout
- 6. Implementing Cache Warming
- Example: Basic Cache Warming Configuration
- 7. Using Edge Side Includes
- Example: Basic ESI Configuration
- Example: ESI with Substitution
- ESI Use Cases
- 8. Configuring Slice Module
- Example: Basic Slice Module Configuration
- 9. Setting Cache Vary Headers
- Example: Setting Vary Header for Content Encoding
- 10. Monitoring Cache Hit Ratio
- Example: Nginx Cache Metrics Configuration
- Cache Hit Ratio Monitoring Best Practices
- 11. Implementing Cache Stampede Prevention
- Example: Basic Cache Stampede Prevention with Nginx
- Key Points for Cache Stampede Prevention
- 12. Configuring Cache Min Uses
- Example: Setting proxy_cache_min_uses
Enabling Compression
- 1. Enabling Gzip
- Example: Basic Gzip Configuration
- 2. Setting Gzip Compression Level
- Example: Setting Gzip Compression Level
- 3. Configuring Gzip Types
- Example: gzip_types configuration
- 4. Setting Minimum Length
- Example: Configuring gzip_min_length
- 5. Enabling Gzip Vary Header
- Example: Enabling Gzip Vary Header
- 6. Configuring Gzip Buffers
- Example: Setting Gzip Buffers
- 7. Disabling Gzip for IE6
- Example: Disabling Gzip for IE6
- 8. Using Gzip Static
- Example: Enabling gzip_static
- 9. Configuring Brotli Compression
- Example: Basic Brotli Configuration
- 10. Setting Brotli Quality
- Example: Brotli Compression Configuration
- 11. Configuring Brotli Types
- Example: Brotli Types Configuration
- 12. Understanding Compression Trade-offs
- Compression Algorithms Comparison
Configuring Access Control
- 1. Allowing IP Addresses
- Example: Allow specific IP address
- Example: Allow IP range using CIDR
- 2. Denying IP Addresses
- Example: Deny specific IP address
- Example: Deny IP range
- 3. Using CIDR Notation
- Example: Restricting Access by CIDR
- 4. Setting Allow/Deny Order
- Example: Basic allow/deny configuration
- Order of Processing
- 5. Implementing HTTP Basic Auth
- Example: Basic Auth Configuration
- 6. Setting Auth User File
- Example: Basic Authentication Setup
- 7. Creating htpasswd File
- Example: Creating htpasswd File
- Example: Adding User to Existing File
- 8. Using Auth Request Module
- Example: Basic auth request configuration
- Example: Setting variables from auth response
- 9. Configuring Satisfy Directive
- Example: Using
- 10. Restricting by User Agent
- Example: Restricting access by user agent
- Example: Allowing only specific user agents
- 11. Implementing Token-based Authentication
- Example: Basic Token Authentication Setup
- Example: Token Authentication with Custom Header
- 12. Using Subrequest Authentication
- Example: Basic auth_request usage
- Example: Setting auth headers with auth_request_set
Implementing Rate Limiting
- 1. Defining Limit Request Zone
- Example: Basic rate limiting zone
- Example: Rate limiting with burst
- 2. Applying Rate Limit
- Example: Basic Rate Limit Configuration
- 3. Setting Burst Parameter
- Example: Configuring Burst Limit
- 4. Using No Delay Option
- Example: Using nodelay in limit_req
- 5. Configuring Connection Limit
- Example: Basic Connection Limiting
- Example: Burst Connection Limiting
- 6. Applying Connection Limit
- Example: Configuring Connection Limits
- Key Points
- 7. Setting Rate Limit Status
- Example: Configuring 429 Status Code
- 8. Logging Rate Limit Events
- Example: Configuring Log Level
- Example: Custom Log Format
- 9. Using Multiple Rate Limits
- Example: Applying Multiple Rate Limits
- 10. Excluding IPs from Rate Limiting
- Example: Exclude Specific IPs from Rate Limiting
- Key Points
- 11. Implementing Dynamic Rate Limits
- Example: Dynamic Rate Limiting Configuration
- 12. Using Delay Parameter
- Example: Configuring rate limiting with delay
Configuring Bandwidth Limiting
- 1. Setting Download Rate Limit
- Example: Configuring Download Rate Limit
- 2. Using After Limit
- Example: Configuring
- 3. Implementing Per-connection Limits
- Example: Setting Per-connection Bandwidth Limits
- 4. Using Variables for Dynamic Limits
- Example: Setting Dynamic Rate Limits
- Example: Using Variables in Map Block
- 5. Configuring Upload Limits
- Example: Setting Upload Size Limit
- 6. Setting Connection-based Throttling
- Example: Basic Connection Throttling
- Example: Connection Throttling with Custom Status
- 7. Implementing Fair Queuing
- Example: Fair Queuing Configuration
- Key Points
- 8. Using Map for Rate Tiers
- Example: Rate Limiting with Map
- 9. Monitoring Bandwidth Usage
- Example: Setting up bandwidth tracking zone
- Monitoring Bandwidth Usage
- 10. Implementing Burst Allowance
- Example: Configuring Burst Allowance
- 11. Configuring Limits per Location
- Example: Setting bandwidth limits for a location block
- 12. Using Conditional Bandwidth Limits
- Example: Conditional bandwidth limit based on user agent
Configuring Logging
- 1. Setting Access Log
- Example: Basic Access Log Configuration
- Example: Custom Log Format
- 2. Setting Error Log
- Example: Basic error log configuration
- Example: Multiple error logs with different levels
- Log Levels
- 3. Defining Log Format
- Example: Custom Log Format Definition
- Common Log Format Variables
- 4. Using JSON Log Format
- Example: JSON Log Format Configuration
- 5. Disabling Logs
- Example: Disabling All Logs
- 6. Implementing Conditional Logging
- Example: Conditional Logging Based on Status Code
- Example: Custom Log Format with Conditional Fields
- 7. Setting Log Buffer
- Example: Setting Log Buffer Size
- Log Buffer Configuration Summary
- 8. Using Syslog
- Example: Syslog Configuration
- 9. Configuring Log Rotation
- Example: Basic Log Format Definition
- Example: Log Rotation with
- 10. Logging to Multiple Files
- Example: Logging to Multiple Files with Different Formats
- 11. Using Custom Variables in Logs
- Example: Defining and Using Custom Variables
- 12. Implementing Structured Logging
- Example: JSON Log Format
- Example: Structured Log with Custom Fields
Implementing Security Best Practices
- 1. Hiding Nginx Version
- Example: Hide Nginx Version
- 2. Disabling Unwanted Methods
- Example: Restricting HTTP Methods
- 3. Preventing Clickjacking
- Example: X-Frame-Options DENY
- Example: Content-Security-Policy frame-ancestors
- 4. Enabling XSS Protection
- Example: Configuring XSS Protection Headers
- 5. Setting Content Type Options
- Example: Configuring X-Content-Type-Options
- 6. Configuring SSL Security
- Example: Basic SSL Configuration
- 7. Implementing HSTS
- Example: Basic HSTS Configuration
- Example: HSTS with Preload
- 8. Restricting File Access
- Example: Restricting Access to .env Files
- Example: Restricting Access to Configuration Files
- Example: Rate Limiting Requests
- 9. Securing Admin Paths
- Example: Basic Auth for Admin
- Example: IP Restriction for Admin
- Example: Rate Limiting for Admin
- 10. Preventing Buffer Overflow
- Example: Configuring Buffer Limits
- 11. Using Secure Headers
- Example: Setting Secure Headers in Nginx
- 12. Implementing DDoS Protection
- Example: Basic DDoS Protection Configuration
- Example: Rate Limiting with Different Zones
- DDoS Protection Strategies
Implementing Advanced Security
- 1. Using ModSecurity WAF Integration
- Example: Basic ModSecurity Configuration
- Example: ModSecurity Rules File
- ModSecurity Integration Summary
- 2. Implementing Request Filtering
- Example: Rate Limiting Configuration
- Example: IP-Based Access Control
- 3. Blocking SQL Injection
- Example: Basic SQL Injection Blocking
- 4. Preventing XSS Attacks
- Example: Setting Security Headers
- XSS Prevention Techniques
- 5. Using Naxsi WAF Module
- Example: Basic Naxsi Configuration
- Example: Learning Mode Configuration
- Key Features of Naxsi
- 6. Implementing IP Reputation Blocking
- Example: Blocking IPs from Known Malicious Countries
- 7. Using Security Headers Bundle
- Example: Basic Security Headers Configuration
- Security Header Best Practices
- 8. Configuring Bot Protection
- Example: Basic Bot Protection Configuration
- 9. Implementing Request Validation
- Example: Rate Limiting Configuration
- Example: Geo-based Access Control
- 10. Using Encrypted SNI
- Example: Basic SSL Configuration
- 11. Hardening Worker Process
- Example: Hardened worker process configuration
- 12. Preventing Path Traversal Attacks
- Example: Secure File Serving with Root
- Example: Preventing Path Traversal with Alias
- Best Practices for Path Traversal Prevention
Optimizing Performance
- 1. Setting Worker Processes
- Example: Setting worker processes to auto
- Example: Setting worker processes to 4
- 2. Configuring Worker Connections
- Example: Basic worker_connections configuration
- 3. Enabling Sendfile
- Example: Enabling sendfile
- 4. Using TCP Optimizations
- Example: Enabling TCP optimizations
- 5. Configuring Keepalive
- Example: Basic Keepalive Configuration
- Example: Disabling Keepalive for Specific Browsers
- 6. Setting Buffer Sizes
- Example: Configuring Buffer Sizes
- 7. Enabling Open File Cache
- Example: Basic Open File Cache Configuration
- 8. Using Gzip Compression
- Example: Enabling Gzip Compression
- 9. Implementing Caching
- Example: Basic Caching Configuration
- Example: Cache Busting with Versioning
- 10. Optimizing SSL Performance
- Example: SSL Configuration
- 11. Using HTTP/2
- Example: Enabling HTTP/2 in Nginx
- 12. Configuring Worker Priority
- Example: Setting Worker Priority
Tuning Kernel Parameters
- 1. Increasing File Descriptors
- Example: Increasing File Descriptors
- 2. Configuring Backlog Queue
- Example: Increasing Backlog Limits
- 3. Setting TCP Buffer Sizes
- Example: Setting TCP Buffer Sizes in sysctl.conf
- 4. Enabling TCP Fast Open
- Example: Enabling TCP Fast Open for TLS
- 5. Configuring Keepalive Parameters
- Example: Setting Keepalive Parameters
- 6. Setting Connection Tracking
- Example: Adjusting Connection Tracking Limits
- 7. Optimizing Memory Settings
- Example: Memory Optimization Configuration
- 8. Using AIO and DirectIO
- Example: Configuring AIO and DirectIO
- 9. Configuring Thread Pool
- Example: Defining a Thread Pool
- Example: Using the Thread Pool
- 10. Setting Accept Mutex
- Example: Enabling Accept Mutex
- Example: Disabling Accept Mutex
- 11. Configuring Multi Accept
- Example: Enabling multi_accept
- 12. Setting Worker RLimit Nofile
- Example: Configuring worker_rlimit_nofile
Optimizing for CDN Integration
- 1. Setting Appropriate Cache Headers
- Example: Setting Cache Headers in Nginx
- Example: Cache Control for Dynamic Content
- 2. Configuring Vary Headers
- Example: Setting Vary Header for Compression
- Example: Manual Vary Header
- 3. Implementing Origin Shield
- Example: Basic Origin Shield Configuration
- Example: Origin Shield with Custom Cache Key
- 4. Using X-Accel Headers
- Example: Serving files via X-Accel-Redirect
- 5. Setting CORS for CDN
- Example: Configuring CORS Headers in Nginx
- 6. Configuring Cache Purge Endpoints
- Example: Basic Cache Purge Configuration
- 7. Using Cache Keys for CDN
- Example: Custom Cache Key for CDN
- 8. Implementing Signed URLs
- Example: Basic Signed URL Validation
- Key Considerations
- 9. Setting Long Expires for Static Assets
- Example: Setting long expiration for static assets
- Example: Using
- 10. Optimizing Image Delivery
- Example: Resizing Images on the Fly
- Example: Serving WebP Images
- Image Optimization Best Practices
- 11. Implementing Conditional GET
- Example: Conditional GET with try_files
- 12. Using CDN-specific Headers
- Example: Setting CDN-specific Headers
Working with Nginx Modules
- 1. Understanding Core Modules
- Example: Basic HTTP module configuration
- 2. Using ngx_http_rewrite_module
- Common Use Cases
- 3. Using ngx_http_ssl_module
- Example: Basic SSL Configuration
- 4. Using ngx_http_gzip_module
- Example: Basic gzip configuration
- 5. Using ngx_http_proxy_module
- Example: Basic proxy configuration
- Example: Proxy with timeout settings
- 6. Using ngx_http_fastcgi_module
- Example: Basic FastCGI Configuration
- 7. Using ngx_http_auth_basic_module
- Example: Basic Authentication Setup
- Example: Creating htpasswd File
- 8. Using ngx_http_access_module
- Example: Basic IP Allow/Deny Rules
- Example: Using
- 9. Loading Dynamic Modules
- Example: Loading a Dynamic Module
- 10. Compiling Third-party Modules
- Example: Compiling a Third-party Module
- 11. Using ngx_http_realip_module
- Example: Configuring real IP handling
- 12. Using ngx_http_stub_status_module
- Example: Enabling stub_status
- Sample Output
Working with Content Modification
- 1. Using Sub Filter
- Example: Basic sub_filter usage
- Example: Sub filter with multiple replacements
- 2. Configuring Multiple Sub Filters
- Example: Multiple Sub Filters Configuration
- 3. Setting Sub Filter Types
- Example: Basic sub_filter usage
- Example: Using sub_filter_types
- 4. Using Addition Module
- Example: Adding text to response
- Example: Adding HTML to response
- 5. Implementing SSI
- Example: Basic SSI Include
- Example: Using Variables
- 6. Configuring SSI Variables
- Example: Using SSI Variables in Content
- Example: Inserting Date Using SSI Variable
- 7. Using XSLT Module
- Example: Basic XSLT Transformation
- 8. Implementing Charset Conversion
- Example: Setting charset for a location
- Example: Using charset_map
- 9. Configuring Content Substitution Patterns
- Example: Basic content replacement
- Example: Substitution in specific content types
- 10. Filtering Response Content
- Example: Using sub_filter to modify content
- 11. Adding Headers and Footers
- Example: Adding a Custom Header
- Example: Adding Headers Conditionally
- 12. Modifying Upstream Responses
- Example: Intercepting and Modifying Error Responses
- Example: Modifying Response with post_action
Working with Image Processing
- 1. Using Image Filter Module
- Example: Basic Image Filtering Configuration
- Example: Image Scaling and Rotation
- 2. Resizing Images
- Example: Resizing Images
- 3. Rotating Images
- Example: Rotating Images
- 4. Cropping Images
- Example: Cropping an Image
- 5. Adjusting Image Quality
- Example: Setting JPEG Quality
- Example: Setting WebP Quality
- 6. Setting Image Buffer Size
- Example: Configuring Image Buffer Size
- 7. Creating Thumbnails
- Example: Thumbnail Creation
- 8. Testing Image Validity
- Example: Testing Image Validity
- 9. Converting Image Formats
- Example: Converting JPEG to WebP
- 10. Configuring Sharpen
- Example: Basic Sharpen Configuration
- 11. Setting Interlace Mode
- Example: Enabling Interlace Mode
- 12. Handling Image Errors
- Example: Custom Error Pages for Images
Working with Nginx Streams (TCP/UDP)
- 1. Configuring Stream Block
- Example: Basic Stream Configuration
- 2. Implementing TCP Load Balancing
- Example: Basic TCP Load Balancing Configuration
- Example: TCP Load Balancing with Sticky Sessions
- Example: TCP Load Balancing with Health Checks
- 3. Implementing UDP Load Balancing
- Example: Basic UDP Load Balancing Configuration
- Example: UDP Load Balancing with Weighted Servers
- 4. Setting Stream Proxy
- Example: Basic Stream Proxy Configuration
- 5. Configuring Stream SSL
- Example: Basic SSL Stream Configuration
- 6. Using SNI Routing
- Example: Basic SNI-based TCP Stream Configuration
- 7. Setting Stream Access Control
- Example: Basic Stream Access Control
- 8. Configuring Stream Logging
- Example: Basic Stream Logging Configuration
- 9. Implementing Health Checks
- Example: Basic TCP Health Check Configuration
- Example: UDP Health Check with Custom Timeout
- Health Check Best Practices
- 10. Setting Stream Timeouts
- Example: Configuring Stream Timeouts
- 11. Using Stream Map
- Example: Basic Stream Map Usage
- 12. Implementing Stream Rate Limiting
- Example: Limiting Connections per IP
- Example: Rate Limiting Requests
Configuring Mail Proxy
- 1. Enabling Mail Module
- Example: Enabling Mail Module in Nginx Configuration
- 2. Configuring SMTP Proxy
- Example: Basic SMTP Proxy Configuration
- Example: SMTP Proxy with SSL
- Example: SMTP Proxy with Authentication
- 3. Configuring IMAP Proxy
- Example: Basic IMAP Proxy Configuration
- 4. Configuring POP3 Proxy
- Example: Basic POP3 Proxy Configuration
- 5. Setting Auth HTTP Backend
- Example: Basic Auth HTTP Configuration
- 6. Configuring SSL for Mail
- Example: Basic SSL Configuration for Mail Proxy
- 7. Setting Mail Timeouts
- Example: Configuring Mail Proxy Timeouts
- 8. Using STARTTLS
- Example: Enabling STARTTLS in Nginx Mail Proxy
- 9. Configuring Mail Server Pools
- Example: Basic Mail Server Pool Configuration
- 10. Logging Mail Proxy Activity
- Example: Configuring Mail Proxy Logging
- Mail Proxy Logging Configuration Summary
- 11. Implementing Mail Routing
- Example: Basic Mail Routing Configuration
- Example: IMAP Mail Routing with Protocol Support
- 12. Handling Mail Authentication Failures
- Example: Configuring Authentication with HTTP
Working with GeoIP
- 1. Installing GeoIP Module
- Example: Compile Nginx with GeoIP Module
- 2. Loading GeoIP Database
- Example: Loading GeoIP Database
- 3. Using GeoIP Variables
- Example: Setting a variable based on country
- 4. Implementing Geo-blocking
- Example: Blocking Access from Specific Countries
- 5. Redirecting by Location
- Example: Redirect based on country code
- 6. Setting Language by Country
- Example: Setting Language Based on Country
- 7. Using GeoIP2 Module
- Example: Setting up GeoIP2 Module
- GeoIP2 Module Summary
- 8. Configuring MaxMind Databases
- Example: Setting up MaxMind Country Database
- 9. Logging GeoIP Data
- Example: Logging GeoIP in Access Log
- 10. Using GeoIP with Map Directive
- Example: Setting up GeoIP map directive
- Example: Using the mapped variable in a location block
- 11. Implementing Regional Content Delivery
- Example: Serving Content Based on Country
- 12. Caching GeoIP Lookups
- Example: Caching GeoIP in Nginx
Implementing A/B Testing
- 1. Using Split Clients
- Example: Basic Split Client Configuration
- 2. Distributing Traffic
- Example: Using ip_hash for A/B Testing
- 3. Setting Cookie-based Routing
- Example: Setting a Cookie for A/B Testing
- 4. Using Header-based Routing
- Example: Route by User-Agent Header
- Header-based Routing Configuration
- 5. Implementing Feature Flags
- Example: Feature Flag Configuration
- Feature Flag Use Cases
- 6. Routing to Multiple Upstreams
- Example: Load Balancing Across Multiple Upstreams
- Example: Using Sticky Sessions with Upstreams
- 7. Tracking A/B Test Results
- Example: Logging A/B Test Events
- Key Metrics to Track
- 8. Using Variables for Variants
- Example: Setting and Using Variables
- 9. Implementing Canary Deployments
- Example: Canary Deployment with Weighted Distribution
- Canary Deployment Strategy
- 10. Rolling Out Changes Gradually
- Example: Gradual Rollout with Weighted Distribution
- 11. Persisting User Assignment
- Example: Setting a Cookie for A/B Test Assignment
- Example: Retrieving Assignment from Cookie
- 12. Measuring A/B Test Metrics
- Example: Conversion Rate Calculation in Nginx
- Key Metrics Summary
Working with Request Processing
- 1. Understanding Request Processing Phases
- Example: Basic Request Flow Configuration
- 2. Using Post Read Phase
- Example: post_action directive usage
- Example: post_action_if directive usage
- 3. Using Server Rewrite Phase
- Example: Basic Rewrite Rule
- Example: Rewrite with Permanent Redirect
- 4. Using Find Config Phase
- Example: Enabling Find Config Phase
- 5. Using Rewrite Phase
- Rewrite Phase Workflow
- 6. Using Post Rewrite Phase
- Example: Setting a Post-Action
- Example: Conditional Post-Action
- 7. Using Preaccess Phase
- Example: Using access_by_lua to check a header
- 8. Using Access Phase
- Example: Basic access_log configuration
- Example: Custom log format
- 9. Using Post Access Phase
- Example: Setting a Post-Action
- Example: Conditional Post-Action
- 10. Using Content Phase
- Example: Serving Static Files
- Example: Custom Error Page
- 11. Using Log Phase
- Example: Custom Log Format
- Example: Error Log Level
- 12. Understanding Phase Handlers
- Example: Configuring Rewrite and Access Phase Handlers
Implementing API Gateway Patterns
- 1. Routing API Requests
- Example: Basic API Route
- Example: Rewrite and Forward
- 2. Implementing API Versioning
- Example: URL Path Versioning
- 3. Rate Limiting API Endpoints
- Example: Basic Rate Limiting Configuration
- Example: Rate Limiting with Burst and Delay
- Rate Limiting Configuration Summary
- 4. Authenticating API Requests
- Example: JWT Authentication Setup
- 5. Implementing API Key Validation
- Example: Basic API Key Validation Setup
- Example: Validating API Key from Header
- 6. Configuring Request Transformation
- Example: Transforming Request Headers
- 7. Implementing Response Transformation
- Example: Transforming Response Headers
- Example: Rewriting URI for Response Transformation
- 8. Handling CORS for APIs
- Example: Basic CORS Configuration
- Example: Handling Preflight Requests
- 9. Implementing Request Routing by Header
- Example: Route by User-Agent Header
- Example: Using Map for Header-Based Routing
- 10. Using Upstream Groups for Microservices
- Example: Load Balancing with Upstream Groups
- Upstream Group Configuration Summary
- 11. Implementing Circuit Breaker
- Example: Basic Circuit Breaker Configuration
- Key Features of Circuit Breaker in Nginx
- 12. Logging API Metrics
- Example: Custom Log Format for API Metrics
- Example: Using Custom Log Format
- Key Metrics to Track
- Steps to Implement API Metrics Logging
Monitoring and Status
- 1. Enabling Stub Status
- Example: Enabling Stub Status
- 2. Understanding Status Metrics
- Example: Enabling stub_status
- 3. Using Access Logs for Monitoring
- Example: Custom Log Format
- Example: Log Rotation with logrotate
- Key Points for Log Monitoring
- 4. Parsing Nginx Logs
- Example: Log Format Configuration
- Example: Log Parsing with Python
- 5. Integrating with Prometheus
- Example: Basic Prometheus Integration
- Key Metrics Exposed
- 6. Integrating with Grafana Dashboards
- Example: Nginx Exporter Configuration
- Example: Grafana Dashboard JSON
- Comparison: Nginx Exporter vs InfluxDB
- 7. Using Third-party Status Modules
- Example: Enabling Virtual Host Traffic Status
- 8. Monitoring Upstream Health
- Example: Basic upstream health check configuration
- Example: Advanced upstream health check with custom parameters
- Upstream Health Check Configuration Summary
- 9. Tracking Response Times
- Example: Configuring response time logging
- Response Time Metrics
- 10. Monitoring SSL Certificate Expiry
- Example: Check Certificate Expiry via Command Line
- Example: Set Up a Cron Job to Monitor Certificates
- 11. Setting Up Alerts
- Example: Basic Alert Configuration
- Example: Alert Threshold Configuration
- 12. Implementing Real-time Metrics
- Example: Configuring Prometheus Exporter
- Example: Using OpenTelemetry Collector
- Real-time Metrics Overview
Implementing Observability
- 1. Configuring OpenTelemetry Integration
- Example: Basic OpenTelemetry Configuration
- 2. Implementing Distributed Tracing
- Example: Basic OpenTracing Configuration
- Tracing Integration Options
- Distributed Tracing Options in Nginx
- 3. Adding Trace Headers
- Example: Adding Trace Headers to Nginx
- 4. Using Jaeger for Tracing
- Example: Basic Jaeger Tracing Configuration
- 5. Integrating with Zipkin
- Example: Nginx Configuration for Zipkin Integration
- 6. Configuring Span Context Propagation
- Example: Enabling Span Context Propagation
- 7. Setting Up Log Correlation
- Example: Log Format with Trace ID
- Workflow: Enabling Structured Logging in Nginx
- 8. Implementing Request Flow Tracking
- Example: Custom Log Format with Trace ID
- Example: Access Log with Request ID
- Key Points for Request Flow Tracking
- 9. Using OpenTracing Module
- Example: Basic OpenTracing Configuration
- 10. Monitoring Latency Distributions
- Example: Logging Latency with Custom Format
- Latency Monitoring Best Practices
- 11. Configuring Trace Sampling
- Example: Setting Trace Sampling Ratio
- 12. Exporting Metrics to Backends
- Example: Prometheus Exporter Configuration
Debugging Nginx
- 1. Testing Configuration
- Example: Testing Nginx Configuration
- 2. Enabling Debug Log
- Example: Enabling Debug Log
- 3. Using Rewrite Log
- Example: Enabling Rewrite Log
- 4. Checking Error Logs
- Example: Viewing Nginx Error Logs
- Example: Filtering Logs by Time
- 5. Debugging SSL Issues
- Example: SSL debug logging
- Common SSL Debugging Steps
- 6. Testing with Curl
- Example: Basic curl request to Nginx
- Example: Simulate a POST request
- 7. Using Nginx Debug Build
- Example: Enabling debug logging in Nginx
- 8. Analyzing Core Dumps
- Example: Analyzing Core Dump with GDB
- 9. Debugging Proxy Issues
- Example: Enable Detailed Proxy Logging
- Common Proxy Debugging Steps
- 10. Using tcpdump for Network Analysis
- Example: Capture Nginx Traffic
- 11. Debugging Location Matching
- Example: Debugging Location Matching
- 12. Using Echo Module for Testing
- Example: Basic Echo Module Usage
Troubleshooting Common Issues
- 1. Resolving 502 Bad Gateway
- Example: Nginx config with timeout adjustments
- 2. Fixing 504 Gateway Timeout
- Example: Increasing proxy timeout values
- 3. Debugging 413 Request Entity Too Large
- Example: Increasing body size limit
- 4. Resolving Configuration Conflicts
- Example: Resolving Duplicate Server Blocks
- 5. Fixing Permission Denied Errors
- Example: Setting Correct Permissions
- 6. Debugging SSL Handshake Failures
- Example: Enabling SSL debug logging
- Example: Checking SSL certificate chain
- 7. Resolving DNS Resolution Issues
- Example: Configuring DNS resolver
- 8. Fixing WebSocket Connection Drops
- Example: Nginx config for WebSocket keep-alive
- 9. Debugging Redirect Loops
- Example: Redirect Loop Configuration
- Debugging Steps
- 10. Resolving Upstream Connection Refused
- Example: Basic Upstream Configuration
- 11. Fixing 400 Bad Request Errors
- Example: Configuring Client Max Body Size
- Example: Logging Request Details
- 12. Troubleshooting Slow Connections
- Example: Enabling sendfile for faster file delivery
- Common Slow Connection Fixes
Working with Containers and Orchestration
- 1. Running Nginx in Docker
- Example: Basic Nginx Container
- Example: Custom Nginx Configuration
- 2. Creating Custom Nginx Image
- Example: Basic Dockerfile for Nginx
- Example: Multi-stage Build for Nginx
- 3. Mounting Configuration
- Example: Mounting Configuration in Docker
- 4. Using Environment Variables
- Example: Setting Environment Variables in Docker
- Example: Using Environment Variables in Nginx Config
- 5. Configuring Health Checks
- Example: Basic Health Check Configuration
- Example: Advanced Health Check with Custom Path and Timeout
- 6. Deploying on Kubernetes
- Example: Ingress Configuration
- Example: Service Configuration
- 7. Using Nginx Ingress Controller
- Example: Basic Ingress Configuration
- Example: Ingress with TLS
- Key Features
- 8. Configuring ConfigMaps
- Example: Mounting ConfigMap in Nginx Deployment
- 9. Implementing Rolling Updates
- Example: Nginx Config for Rolling Updates
- Rolling Update Strategy
- 10. Setting Resource Limits
- Example: Rate Limiting Configuration
- Example: Connection Limiting Configuration
- 11. Using Nginx in Docker Compose
- Example: Basic Nginx Docker Compose Setup
- Example: Nginx with Reverse Proxy Configuration
- Key Points for Nginx in Docker Compose
- 12. Implementing Sidecar Patterns
- Example: Sidecar Configuration in Kubernetes
- Sidecar Benefits
Implementing High Availability
- 1. Configuring Nginx Active-Passive
- Example: Active-Passive Configuration
- 2. Implementing Active-Active Setup
- Example: Active-Active Configuration
- 3. Using Virtual IP
- Example: Virtual IP Configuration
- 4. Configuring Health Check Scripts
- Example: Health Check Configuration
- 5. Implementing Session Persistence
- Example: Session Persistence Configuration
- 6. Using DNS Round Robin
- Example: DNS Round Robin Configuration
- 7. Configuring Upstream Retry
- Example: Upstream Retry Configuration
- 8. Implementing Circuit Breaker Pattern
- Example: Circuit Breaker Configuration
- 9. Using Zone Sync for Cluster State
- Example: Zone Sync Configuration
- 10. Monitoring Failover Events
- Example: Failover Monitoring Configuration
- 11. Implementing Graceful Degradation
- Example: Graceful Degradation Configuration
- 12. Configuring Connection Draining
- Example: Connection Draining Configuration
Implementing Service Mesh Integration
- 1. Using Nginx as Sidecar Proxy
- Example: Basic Sidecar Configuration
- 2. Configuring mTLS
- Example: mTLS Configuration in Nginx
- 3. Implementing Service Discovery
- Example: Service Discovery with Consul
- 4. Using Consul Template Integration
- Example: Consul Template Configuration
- Example: Consul Template File (app.ctmpl)
- 5. Configuring Dynamic Upstream Updates
- Example: Basic Upstream Configuration
- Example: Using Keepalive Connections
- Dynamic Upstream Update Considerations
- 6. Implementing Traffic Shadowing
- Example: Shadowing traffic to a secondary service
- Key Considerations for Traffic Shadowing
- 7. Using Nginx with Istio
- Example: Ingress with Istio integration
- 8. Configuring OpenTracing Integration
- Example: Jaeger Tracer Configuration
- Example: Nginx Configuration with OpenTracing
- 9. Implementing Request Tracing
- Example: Basic OpenTracing Configuration
- Example: Propagating Trace Context
- Key Concepts
- 10. Using Jaeger for Distributed Tracing
- Example: Configuring Jaeger Tracing in Nginx
- 11. Implementing Traffic Mirroring
- Example: Mirroring Traffic to a Logging Service
- 12. Configuring Circuit Breakers
- Example: Basic Circuit Breaker Configuration
Migrating and Upgrading Nginx
- 1. Planning Nginx Version Upgrades
- Upgrade Planning Steps
- 2. Testing Configuration Compatibility
- Example: Testing Configuration
- Compatibility Testing Steps
- 3. Performing Zero-downtime Upgrades
- Example: Zero-downtime upgrade command
- 4. Migrating Configuration Between Servers
- Example: Securely copying configuration files
- 5. Converting Apache to Nginx Configuration
- Example: Basic Apache to Nginx Conversion
- Example: Equivalent Nginx Configuration
- Key Differences in Configuration Syntax
- 6. Handling Deprecated Directives
- Example: Migrating from
- 7. Rolling Back Failed Upgrades
- Example: Reverting Nginx Configuration After Failed Upgrade
- 8. Upgrading Dynamic Modules
- Example: Recompiling Dynamic Module
- 9. Migrating SSL Certificates
- 10. Testing Upgrade Impact
- Example: Simulate upgrade with config test
- Example: Check module compatibility
- Upgrade Testing Approaches
- 11. Documenting Configuration Changes
- Example: Logging Configuration Changes
- Best Practices for Configuration Documentation
- 12. Implementing Blue-Green Deployments
- Example: Blue-Green Deployment Configuration
- Blue-Green Deployment Workflow