Reverse proxy delivery
What you need to know
A reverse proxy accepts client HTTP requests and forwards them to a private Next.js server. It can terminate TLS, enforce connection and body limits, and control streaming without becoming the application authorization layer.
By the end, you can: plan trusted headers and streaming; test deep links and status.
Loopback location inside a lab server block
location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Forwarded ""; proxy_buffering off; proxy_read_timeout 15s; client_max_body_size 1m;}Expected behavior: Partial Nginx config for one trusted ingress hop, not a general production configuration. Streaming bytes can pass without response buffering.
How it works
For the isolated lab, Nginx listens on 127.0.0.1:8080 and forwards to 127.0.0.1:3000. In production, configure TLS and a reviewed hostname, replace untrusted forwarding headers at the first trusted boundary, and only accept trusted upstream hops. Do not trust an arbitrary incoming X-Forwarded-For as identity. Preserve the validated request Host needed by the application and verify origin checks for Server Actions. In a deployed ingress, explicitly reject unrecognized hosts in the default server before forwarding; a server_name entry alone does not guarantee rejection. The loopback location example assumes a separate trusted host-selection boundary. Proxy buffering can hold chunks and hide progressive rendering; disable it for streaming routes where necessary and check every downstream intermediary. Keep bounded timeouts and body limits. Let the application's Cache-Control policy govern response caching unless a reviewed explicit exception exists. Never cache personalized responses in a shared proxy based on path alone. A proxy error, an app 404 and a successful response have distinct diagnostic meaning.
Inspect a lab response without following redirects
curl --max-time 5 -i http://127.0.0.1:8080/catalogcurl --max-time 5 -i http://127.0.0.1:8080/missingcurl --max-time 5 -N http://127.0.0.1:8080/api/streamExpected behavior: Expected from an approved fixture: 200, 404, and incremental stream output respectively. Status and arrival time must be measured, not assumed.
Common mistake
Do not expose the upstream publicly or allow every client-supplied forwarding header through. Do not solve a Server Action origin mismatch by permitting every origin; inspect host, scheme and trusted forwarding first.
Practice and verification
Use the loopback proxy fixture and synthetic origin. Assert response status, header replacement, missing-path behavior and progressive chunks. Then describe the additional tests needed against a real Next.js app and TLS terminator.
Scope: Proposed Next.js 16.x / React 19, App Router with Cache Components disabled unless noted. Framework and browser examples are staged, not executed. Hypothetical costs are not actual provider rates.