Mastering Nginx Reverse Proxy: Architecture, Workflow, and Config Guide

This article provides a comprehensive technical guide to Nginx reverse proxy, explaining forward vs reverse proxy concepts, architecture layers, event‑driven model, detailed configuration examples, and a step‑by‑step request flow that illustrates how Nginx hides backend servers while enabling load balancing and high availability.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mastering Nginx Reverse Proxy: Architecture, Workflow, and Config Guide

Nginx is a core component of large‑scale architectures. This guide explains the principles of Nginx reverse proxy, contrasting it with forward proxy, and shows how Nginx forwards client requests to internal services while keeping backend servers hidden.

In a forward proxy the client configures the proxy itself (e.g., for bypassing firewalls). In a reverse proxy the client only knows the Nginx address; Nginx forwards the request to the real services, which remain invisible to the client.

Nginx reverse proxy diagram
Nginx reverse proxy diagram

The architecture consists of three layers:

Client layer : accesses only the domain name (e.g., mikechen.cc).

Nginx layer : handles all inbound traffic, supports clustering with Keepalived/VIP for high availability.

Backend layer : multiple internal servers listening on private ports (e.g., 8080), completely hidden from the public network.

Nginx uses an event‑driven, asynchronous non‑blocking model (master + worker processes) that can easily support tens of thousands of concurrent connections on a single machine.

Reverse Proxy Principle

The overall workflow is illustrated in the following diagram:

Nginx reverse proxy architecture
Nginx reverse proxy architecture

A typical Nginx configuration for reverse proxy looks like this:

http {
    server {
        listen 80;
        server_name example.com;
        location / {
            proxy_pass http://127.0.0.1:8080;  # backend address
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}

Step‑by‑Step Request Flow

Client initiates an HTTP/HTTPS request to Nginx (port 80/443).

Nginx matches the request using server_name and location rules.

Based on the upstream group and the configured load‑balancing algorithm, Nginx selects a backend server.

Nginx forwards the request with proxy_pass, optionally rewriting headers or the URI.

The backend processes the request and returns a response; Nginx can buffer, compress, or cache the response before sending it to the client.

The client receives the response without ever seeing the real backend servers.

Nginx reverse proxy workflow
Nginx reverse proxy workflow
backend developmentLoad BalancingWeb ArchitectureNginxreverse proxyserver configuration
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.