Kahibaro
Discord Login Register

5.1.5 Reverse proxy concepts

Core Ideas of a Reverse Proxy

A reverse proxy is a server that receives client requests and forwards them to one or more backend servers, then returns the responses as if they came directly from the proxy itself.

Key points that distinguish a reverse proxy from direct access to an application:

Do not confuse with a forward proxy (used by clients to reach arbitrary sites on the internet); a reverse proxy sits in front of your servers, not in front of the client.

Typical technologies used as reverse proxies:

(Their specific configuration is covered in their own chapters.)

Common Use Cases

1. Central Entry Point and Load Balancing

A reverse proxy is often the “front door” to an application cluster.

Typical pattern:

Benefits:

Load balancing logic is part of the reverse proxy; “Load Balancing” has its own section later, but conceptually:

2. TLS Termination (SSL Offload)

The reverse proxy often handles TLS encryption/decryption:

Advantages:

Some deployments also use end-to-end encryption:

In that case the reverse proxy may re-encrypt traffic after inspecting/rewriting it.

3. HTTP Routing and Path-Based Dispatch

Reverse proxies can route traffic to different backends based on:

Examples:

This kind of “smart routing” is a main reason modern applications centralize all traffic through a reverse proxy.

4. Application Firewalling and Security Layer

A reverse proxy acts as a security layer:

Example protective patterns:

5. Caching and Performance Optimization

Reverse proxies can greatly improve performance:

Effects:

6. Protocol Translation and Normalization

Reverse proxies can sit between clients and backends that “speak” slightly different HTTP dialects or even other protocols.

Examples:

They can also add or normalize headers, such as:

Backends must often be configured to trust these headers (or only trust them from known proxies) if they use them to determine client IP or scheme.

Reverse Proxy vs. Other Architectural Components

Reverse Proxy vs. Load Balancer

Many products are both; conceptually:

In practice:

Reverse Proxy vs. API Gateway

An API gateway is essentially a specialized reverse proxy for APIs, with extra concerns:

Conceptually:

Reverse Proxy vs. Forward Proxy

Core differences:

Typical Reverse Proxy Topologies

1. Single Reverse Proxy in Front of One Application

Simple pattern:

Use cases:

2. Single Reverse Proxy in Front of Multiple Applications

Advantages:

3. Reverse Proxies Behind a Layer-4 Load Balancer

For high availability:

Benefits:

4. Reverse Proxies in Microservices Environments

Patterns:

From the server-admin perspective, the “edge proxy” is usually the focus.

Core Concepts: Headers, IPs, and Identity

Client IP and `X-Forwarded-For`

Because all traffic arrives at the backend from the reverse proxy, the backend’s direct remote_addr is the proxy IP.

To preserve the real client IP, proxies add a header:

Best practices:

Original Scheme and Host

With TLS termination and host-based routing:

Common headers:

Backends use these values for:

Path and Header Rewriting

Reverse proxies frequently modify (rewrite) requests or responses.

URI Rewriting

Typical scenarios:

The proxy can:

You must be careful with:

Header Injection/Filtering

The proxy can:

This separation allows backends to focus on application logic, while the proxy enforces consistent edge policies.

Caching Behavior and Considerations

A reverse proxy acting as a cache observes HTTP caching headers:

Important concepts:

Tune caching carefully; misconfiguration can leak private data or cause users to see each other’s responses.

Security Implications and Pitfalls

Benefits

Common Mistakes

Always combine reverse proxy rules with a clear threat model and, when possible, defense in depth on the backend.

Operational Concerns

Observability: Logs and Metrics

Reverse proxies are prime sources for:

Good practice:

Configuration Management

Reverse proxy configurations can grow complex:

Managing them reliably often involves:

High Availability

To avoid a single point of failure:

Also consider:

When to Use a Reverse Proxy

A reverse proxy is especially appropriate when:

In modern server administration, a reverse proxy is almost always part of the web stack; understanding its concepts is key to designing robust, secure, and scalable services.

Views: 116

Comments

Please login to add a comment.

Don't have an account? Register now!