0Pricing
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) · Lesson

Forwarding Headers & Client IP

Learn how Nginx rewrites request headers when proxying, and how to preserve the original client information for upstream applications.

Why Headers Matter

When Nginx acts as a reverse proxy, the upstream server only sees a connection coming from Nginx, not the real client. Without extra configuration, the backend loses the visitor's original IP, host, and protocol.

To keep this information, Nginx must forward headers describing the original request.

The Default Host Header

By default Nginx may pass the upstream server's address as the Host header. Many apps rely on the original host for routing or building absolute URLs.

Set it explicitly so the backend sees what the client requested:

location / {
    proxy_pass http://backend;
    proxy_set_header Host $host;
}

All lessons in this course

  1. Configuring Simple Reverse Proxy
  2. Upstream Servers & Load Balancing
  3. Proxy Buffering & Caching
  4. Forwarding Headers & Client IP
← Back to API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)