Blog/DevOps/Nginx

Nginx

5 essential nginx interview questions

Nginx: high-performance web server and reverse proxy. Lightweight, efficient, fast. Used for: web server (serve static files), reverse proxy (forward requests to backend servers), load balancer (distribute traffic), API gateway. Benefits: handles thousands of concurrent connections, low memory footprint, simple configuration. Popular for microservices and high-traffic applications.
Reverse proxy: forward client requests to backend servers. nginx.conf: upstream backend { server backend1:3000; server backend2:3000; }. location / { proxy_pass http://backend; }. Load balancing: distribute requests. Health checks: skip unhealthy servers. Caching: improve performance. SSL termination: handle HTTPS.
Load balancing algorithms in Nginx: Round robin (default), least_conn, ip_hash, random. Configuration: upstream backend { server srv1; server srv2; server srv3 weight=5; }. weight: priority. Sticky sessions: ip_hash maintains session. Health checks: passive (detect failures), active (probe servers). Monitor with nginx -s reload for graceful reload.
Gzip compression: reduce response size. Caching: cache responses, reduce backend load. Connection pooling: reuse backend connections. Buffer optimization: tuning buffer sizes. Worker processes: match CPU cores. Enable keep-alive: reduce connection overhead. CDN integration: serve static content globally. Monitoring: track requests, errors, latency.
SSL/TLS: enable HTTPS. Security headers: X-Frame-Options, Content-Security-Policy. Rate limiting: limit requests per IP. WAF (Web Application Firewall): protect against attacks. Hide version: disable Server header. Disable unnecessary modules. Regular updates. Least privilege: run as unprivileged user. Monitor logs for suspicious activity.