What Is a Reverse Proxy? Configure Request Paths and Forwarded Headers Safely
A reverse proxy is an intermediary server in front of web servers or application services. It accepts client requests, forwards them to a backend, and returns the backend response to the client. It can give clients one public entry point while hiding backend addresses and applying routing, TLS termination, caching, or load balancing. However, headers that carry the original client IP or external protocol are not automatically trustworthy; configure which proxies are trusted and how those headers are handled.
A reverse proxy is an intermediary server in front of web servers or application services. It accepts client requests, forwards them to a backend, and returns the backend response to the client. It can give clients one public entry point while hiding backend addresses and applying routing, TLS termination, caching, or load balancing. However, headers that carry the original client IP or external protocol are not automatically trustworthy; configure which proxies are trusted and how those headers are handled.
How is a reverse proxy different from a forward proxy?
A forward proxy makes requests to external servers on behalf of clients. A reverse proxy sits in front of servers and provides an entry point to one or more backends. MDN lists load balancing, static-content caching, and compression among reverse proxy use cases, and notes that a proxy can hide the client IP. (MDN: Proxy servers and tunneling)
“Reverse proxy” does not name one product or fixed feature set. A proxy might only forward HTTP traffic, or, depending on the product and configuration, also provide TLS termination, routing, caching, compression, or load balancing. Its functions can overlap with an API gateway, but verify separately whether you need API-specific authentication policies or request aggregation.
In what order do the request and response travel?
The basic flow is client → reverse proxy → backend → reverse proxy → client. The proxy sends the request to a backend, receives its response, and passes that response back. A backend can be exposed only on a private address behind the proxy, but network restrictions and application authorization checks should be designed separately.
When NGINX acts as an HTTP reverse proxy, location and proxy_pass specify where to send a request. The following illustrative configuration assumes NGINX directly receives HTTP requests for example.com and forwards /api/ requests to a local backend at 127.0.0.1:8080. Adjust addresses, TLS, firewall rules, and header policies for the actual deployment. (NGINX Reverse Proxy guide)
server {
listen 80;
server_name example.com;
location /api/ {
proxy_pass http://127.0.0.1:8080/;
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;
}
}The /api/ location and the trailing / in the proxy_pass URL affect path forwarding. In this example, a request to /api/orders is sent to /orders on the backend. When proxy_pass includes a URI, NGINX replaces the part of the request URI that matches the location with that URI. Without a URI in the address, the request URI is passed through. Decide whether a prefix should be preserved or removed, then verify with a representative request. (NGINX Reverse Proxy guide)
Before applying a configuration, test it with the installed NGINX and reload only after the test succeeds. For example, nginx -t checks syntax and whether referenced files can be opened; nginx -s reload can reload a running configuration. This article's configuration snippet was not run or validated in an NGINX environment. (NGINX command-line parameters, NGINX Beginner’s Guide)
How should forwarded headers and the original client IP be handled?
When a proxy connects to a backend, the backend may see the proxy as the network peer. Headers such as Forwarded, X-Forwarded-For, X-Forwarded-Host, and X-Forwarded-Proto can carry the original client IP, requested host, and protocol used by the client. (MDN: Forwarding client information through proxies)
Accurate and safe interpretation depends on knowing the proxy chain. Express documentation explains that its trust proxy setting can make the application rely on forwarded header values and warns that clients can spoof them if the last trusted proxy does not remove or overwrite the headers. Review the setup as follows: (Express: Behind proxies)
Restrict network paths that could connect directly to the backend.
Configure the backend framework's trusted proxy range to match actual proxy addresses or hops. If using a fixed hop count, confirm that requests cannot reach the application through paths with different numbers of proxies.
Do not trust forwarded headers supplied by clients without validation. Configure the public-facing proxy to overwrite them or append values according to a defined trusted-chain policy.
Verify how the original host and protocol affect redirects, absolute URLs, and secure-cookie behavior.
By default, NGINX changes the Host and Connection headers in proxied requests. proxy_set_header can set the values to forward. In the example, X-Forwarded-For appends the client address seen by the current proxy to the existing value. Do not use these headers as the basis for access control, audit records, or rate limits without an agreed proxy-chain model. (NGINX proxy module reference)
How should you check availability and performance?
If the proxy runs as a single instance or lacks capacity, several backends can be affected at once. For high availability, design multiple instances and an upstream load balancer or platform failover, then check capacity with load testing. A reverse proxy does not always serve as a load balancer. In NGINX, distributing traffic across a server group is configured separately, and product capabilities differ. (NGINX Reverse Proxy guide)
Review backend connection timeouts and response buffering for the workload. NGINX buffers proxied responses by default, but buffering can be disabled to pass data to the client as it arrives. Confirm whether streaming or interactive responses require that behavior, and observe how large responses affect memory and temporary-file use. Do not apply retries indiscriminately: consider whether repeating a request is safe and whether the backend might already have processed it. (NGINX proxy module reference)
Checklist before adopting or changing a proxy
Are the public-to-backend paths and ports configured as intended?
Have you confirmed whether the URI in `proxy_pass` preserves or removes the `/api/` prefix?
Is network access restricted so the backend is not exposed directly?
Is it clear who sets forwarded headers and which proxy hops the backend trusts?
Have you checked where TLS terminates, encryption to the backend, certificate validation, and hostname handling?
Do timeouts, buffering, error responses, logs, and correlation IDs fit the service requirements?
Can you check the configuration syntax and verify representative request paths before applying changes?