Skip to content

Linux Reverse Proxy

Reverse Proxy, Load Balancing & API Gateway

Section titled “Reverse Proxy, Load Balancing & API Gateway”

Modern web architectures rely on a combination of components to ensure scalability, reliability, and security. Nginx is frequently used as:

  • A reverse proxy
  • A load balancer
  • An API gateway

This scriptum introduces the essential theoretical concepts behind these roles.


A reverse proxy is a server that sits between clients and backend servers. Clients communicate only with the proxy, which forwards requests to internal servers.

  • Accepts incoming HTTP(S) traffic
  • Forwards requests to backend servers
  • Hides internal network topology
  • Terminates TLS
  • Adds headers or rewrites URLs
  • Implements caching or compression
  • Security: backend servers remain inaccessible from the internet
  • Centralization: all routing and TLS configuration in one place
  • Scalability: easy to add/remove backend servers
  • Uniform interface for multiple backend technologies

Load balancing is the distribution of traffic across multiple backend servers.

Requests go to backends in sequential order.

Requests go to the backend with the fewest active connections.

Uses client IP to route requests consistently to the same backend (sticky sessions).

  • Increase total throughput
  • Reduce load on individual servers
  • Improve fault tolerance
  • Allow horizontal scaling

Nginx can perform many “gateway” tasks before requests reach the backend.

Rate limiting prevents abusive behavior or overload by limiting how many requests a client may send in a defined time window.

Examples:

  • Limit per IP
  • Limit per path
  • Burst control

Nginx can filter:

  • Forbidden HTTP methods
  • Suspicious patterns in URLs
  • Unwanted User-Agents (bots, scrapers)
  • Oversized request bodies

Nginx can add, remove, or rewrite headers:

  • Add security headers (CSP, X-Frame-Options)
  • Remove sensitive client-provided headers
  • Forward IP/identity metadata to backends

Nginx provides multiple layers of security:

Allow only desired methods (e.g., GET, POST).

Block known bots or malicious crawlers.

Allow or deny access based on IP ranges.

Although Nginx is not a full WAF, it can:

  • Block suspicious query strings
  • Prevent directory traversal
  • Enforce CORS policies
  • Limit upload size

A typical system may look like this:

Client → Internet → Nginx → Backend Pool
|
→ Security Policies
|
→ Rate Limiting

Nginx provides robust tools for building scalable, secure, and flexible web infrastructures:

  • Reverse proxy ensures central routing and abstraction
  • Load balancing increases performance and reliability
  • API gateway features add critical security and traffic-management controls