nginx
Installation
SKILL.md
Nginx
Overview
Nginx is a high-performance web server and reverse proxy that serves static files, proxies requests to application servers, load balances across backends, terminates TLS, and caches responses. It handles thousands of concurrent connections with minimal resource usage through an event-driven, non-blocking architecture.
Instructions
- When configuring server blocks, define virtual hosts with
server_namefor domain matching andlistenfor ports, using separate blocks for HTTP (port 80, redirect to HTTPS) and HTTPS (port 443 with SSL and HTTP/2). - When setting up reverse proxying, use
proxy_passto forward to upstream servers and setproxy_set_headerfor Host, X-Real-IP, X-Forwarded-For, and X-Forwarded-Proto to preserve client information. - When load balancing, define
upstreamblocks with multiple servers and choose the strategy: round-robin (default),least_conn,ip_hashfor sticky sessions, or weighted distribution. - When configuring TLS, set modern protocols (
TLSv1.2 TLSv1.3), enablessl_staplingand session caching, and integrate with Let's Encrypt via certbot for automatic certificate renewal. - When serving static files, enable
gzipcompression for text-based content, setexpires 1yfor hashed assets, usesendfile onfor efficient transfer, andtry_filesfor SPA fallback routing. - When adding security, set headers (X-Frame-Options, X-Content-Type-Options, HSTS, CSP) and configure rate limiting with
limit_req_zoneto prevent abuse.