Use Cases and Features of modern NGINX

Use cases and advanced features of NGINX, including load balancing, reverse proxy and more, for high-performance web applications.

NGINX started as a web server in 2004 and slowly became the Swiss Army knife of infrastructure. I have used it as a reverse proxy, a load balancer, an API gateway, and even a DIY CDN. Here is where it actually shines in 2024 and where it is not the right tool.

Web Server

NGINX serves static files efficiently. I have seen it handle 50k+ concurrent connections on a $20/month VPS where Apache would buckle. The event-driven architecture means it does not spawn a thread per connection—it uses a small pool of worker processes.

For dynamic content, NGINX proxies to upstream servers (Gunicorn, uWSGI, Node.js). It is not an application server, but it is a reliable front door.

Reverse Proxy

Reverse proxy is where NGINX earned its reputation. It sits between clients and backend services, forwarding requests and returning responses. I use this pattern for:

  • Shielding backend services from direct exposure
  • Terminating SSL/TLS at the edge
  • Caching responses to reduce backend load
  • Rate limiting to protect against abuse

Load Balancing

NGINX supports round-robin, least connections, IP hash, and weighted distributions. In practice, least connections works well for long-lived connections (WebSocket, gRPC), while round-robin is fine for stateless HTTP APIs.

NGINX Plus adds health checks and session persistence, which matter for production setups.

API Gateway

As microservices multiplied, NGINX became my default API gateway. It routes requests to the right service, handles authentication via JWT, and aggregates responses. Combined with OpenID Connect and Prometheus, it covers the API gateway basics without introducing another component.

Caching

NGINX caches responses at the edge. I have used this for API responses that change infrequently—database query results, external API calls, computed views. Fine-grained cache control (vary by header, cookie, or URL parameter) avoids stale data.

Security

NGINX provides SSL/TLS termination, request filtering, and rate limiting. ModSecurity adds WAF capabilities. I have used rate limiting to mitigate brute-force attacks on login endpoints—simple to configure and effective.

Kubernetes and Containers

NGINX Ingress Controller is the standard for routing external traffic into Kubernetes clusters. I run it in every K8s cluster I manage. Combined with Istio or Linkerd for service mesh, it handles east-west traffic too.

Streaming

NGINX supports HLS and MPEG-DASH for video streaming. I have used it for live event coverage where adaptive bitrate matters. It is not a replacement for a dedicated CDN, but it works for moderate-scale streaming.

When Not to Use NGINX

  • Need a full application server? Use Passenger, Puma, or Unicorn directly.
  • Need advanced WAF features? Use ModSecurity or a dedicated WAF.
  • Need server-side rendering for a JavaScript app? Consider a dedicated SSR layer.

NGINX is not always the answer, but it is usually a good first bet.