Reverse proxy and Linux process
Prerequisite: node-container-build-and-runtime. Objective: Trace local request path. Each example is independent. Tested with Node.js 22.16.0 on Linux. Save as main.mjs in a fresh disposable directory and run node main.mjs. These are static code blocks; external system behavior is not established by a local model.
How it works
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.
Forward a local HTTP request
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();}Expected output:
httpThe proxy overrides client-provided scheme in this fixed HTTP-only topology.
Reject an untrusted forwarding source
import assert from 'node:assert/strict';function scheme(peer,forwarded){return peer==='trusted-edge'&&['http','https'].includes(forwarded)?forwarded:'http';}assert.equal(scheme('direct-client','https'),'http');console.log(scheme('trusted-edge','https'));Expected output:
httpsThe peer string is synthetic; real trust must use actual network topology and configuration.
Common mistake
Do not expose an application publicly while trusting every forwarded header, or restart a service as a substitute for diagnosing it.
Practice
Trace browser → proxy → Node and explain which component owns TLS, authorization and request timeout.
Reference candidate: node-reverse-proxy-and-linux-process-lookup (route unverified). Documentation anchors: https://nginx.org/en/docs/http/ngx_http_proxy_module.html. External versions and full integration are pending.
Administrative staged lab: staged-deployment-labs/nginx/nginx.conf.template. Read its README for prerequisites, execution boundaries and cleanup. Not a verified public route.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Reverse proxy and Linux process — knowledge check
Apply the lesson to a fresh scenario and explain the evidence boundary.
What is a reverse proxy responsible for?
When may forwarded protocol metadata be trusted?
What did the local HTTP fixture verify?