Preserve Encoded Paths in an Existing NGINX HTTP Forwarding Route
Use request_uri when the forwarding contract needs the original path and query, keeping the existing destination validation in place.
A route built from $uri can send a different path from the one the client supplied. For http://service.example/files/a%2Fb?view=raw, the escaped slash is part of that original spelling.
| Variable | Representation |
|---|---|
| $uri | The current normalized URI, which can change during internal processing |
| $request_uri | The original request URI, including its query arguments |
In an existing HTTP forward-proxy arrangement that already selects and validates the destination authority, the original path and query can be preserved with:
proxy_pass http://$http_host$request_uri;$http_host supplies the selected Host-header authority in this arrangement. Retain the listener's client restrictions, destination policy and name-resolution configuration.
Replacing $uri$is_args$args with this expression changes the representation sent; the former uses the normalized path and current arguments. Choose according to the endpoint contract, especially when escaped delimiters matter or a signature covers the original target. Deliberate path rewriting has a different requirement.
This applies to the visible HTTP request. An HTTPS CONNECT tunnel carries the later request inside TLS and requires its own supported handling.