Architecture

Reverse proxy and Linux process

A reverse proxy receives requests and forwards them to an application server. Nginx can terminate TLS and route traffic, while the Node process handles application behavior. Define the trusted proxy hop explicitly. A client can supply forwarding headers; only accept them after the immediate peer and proxy configuration have been verified. In a single trusted edge configuration, overwrite incoming forwarding fields using observed connection details rather than trusting arbitrary values. Keep the application listener private, configure bounded timeouts, and use a supervisor with a dedicated identity. The local example exercises a Node HTTP proxy, not Nginx itself. Do not expose an application publicly while trusting every forwarded header, or restart a service as a substitute for diagnosing it. Sources: https://nginx.org/en/docs/http/ngx_http_proxy_module.html.

Formal Syntax & Structure

nodejs syntaxnodejs
Forward a local HTTP request (conceptual contract; see example)

Working Example

Example Snippetnodejs
import assert from 'node:assert/strict';import http from 'node:http';import {once} from 'node:events';const backend=http.createServer((req,res)=>res.end(req.headers['x-forwarded-proto']??'none'));backend.listen(0,'127.0.0.1');await once(backend,'listening');const proxy=http.createServer((req,res)=>{http.get({host:'127.0.0.1',port:backend.address().port,path:'/',headers:{'x-forwarded-proto':'http'}},up=>up.pipe(res)).on('error',()=>{res.statusCode=502;res.end();});});proxy.listen(0,'127.0.0.1');await once(proxy,'listening');try{const result=await fetch(`http://127.0.0.1:${proxy.address().port}`,{headers:{'x-forwarded-proto':'https'}});const body=await result.text();assert.equal(body,'http');console.log(body);}finally{proxy.closeAllConnections();backend.closeAllConnections();proxy.close();backend.close();}
Node.js Reference