Node.js and Python backend hosting
Choose the protocol before the framework
Nginx can forward HTTP to a Node.js server, Python application server, Go or Rust HTTP binary, JVM application or ASP.NET Core Kestrel. It does not execute those languages. A Python WSGI application is a callable with a synchronous interface; ASGI defines an asynchronous message interface used by servers such as Uvicorn. Neither interface is itself the wire protocol Nginx speaks. Choose an application server that implements the interface and listens on a known private HTTP endpoint.
location /api/ { proxy_pass http://127.0.0.1:19030/; }location /server/ { proxy_pass http://127.0.0.1:19031/; }With these prefixes, /api/items reaches the Node process as /items and /server/reports reaches Python as /reports. Both use HTTP, even though the application languages differ. Start and stop each process separately; a successful Nginx configuration check does not start either one.
A Node.js application with no dependencies
const http = require('node:http');function route(path, method = 'GET') { if (method !== 'GET') return [405, {error: 'method'}]; if (path === '/health') return [200, {ready: true}]; if (path === '/items') return [200, {items: ['pen', 'book']}]; return [404, {error: 'not found'}];}module.exports = {route};if (require.main === module) { const server = http.createServer((req, res) => { const [status, body] = route(new URL(req.url, 'http://node.test').pathname, req.method); res.writeHead(status, {'Content-Type': 'application/json', 'Cache-Control': 'no-store', ...(status === 405 ? {'Allow': 'GET'} : {})}); res.end(JSON.stringify(body)); }); server.listen(19030, '127.0.0.1'); process.on('SIGTERM', () => server.close());}Node uses its built-in HTTP server and a pure routing function. A GET for /items yields 200 and a small JSON list; /health returns a readiness marker; an unknown path yields 404. The fixture binds loopback and uses no database. It is not a full Express deployment, and the static lesson editor does not run it.
A WSGI application behind HTTP
from wsgiref.simple_server import make_server
def app(environ, start_response): path = environ['PATH_INFO'] if environ['REQUEST_METHOD'] != 'GET': status, body = '405 Method Not Allowed', b'Method not allowed' elif path == '/health': status, body = '200 OK', b'ready' elif path == '/reports': status, body = '200 OK', b'<h1>Sample report</h1>' else: status, body = '404 Not Found', b'Not found' headers = [('Content-Type', 'text/html; charset=utf-8' if path == '/reports' and status == '200 OK' else 'text/plain; charset=utf-8'), ('Content-Length', str(len(body))), ('Cache-Control', 'no-store')] if status.startswith('405'): headers.append(('Allow', 'GET')) start_response(status, headers) return [body]
if __name__ == '__main__': # Teaching server only, not a production WSGI server. with make_server('127.0.0.1', 19031, app) as server: server.serve_forever()The standard-library WSGI server translates HTTP into the application callable interface. It is suitable only for this small local demonstration. In a real deployment choose a maintained WSGI server such as Gunicorn, or an ASGI server for an ASGI app. Check its installed version, worker model, forwarded-header trust and mount-path options.
Other gateway protocols
PHP-FPM uses FastCGI (previous chapter). An explicitly configured uwsgi-protocol server needs uwsgi_pass and its parameters; a SCGI server needs scgi_pass and the matching parameter contract. Nginx can retrieve existing values from Memcached using a configured key; it does not populate that store on cache miss. These are separate modules, not alternatives that can be swapped against an HTTP listener.
location /legacy/ { include uwsgi_params; uwsgi_pass 127.0.0.1:19032;}location /scgi/ { include scgi_params; scgi_pass 127.0.0.1:19033;}location = /catalog-snapshot { set $memcached_key catalog-v1; memcached_pass 127.0.0.1:11211;}The parameter files depend on the installation; inspect their contents and server expectations. The Memcached endpoint is illustrative and assumes a separately populated public synthetic value. These snippets are not enabled in the lab.
Practice
Explain which process executes Python, which protocol travels between Nginx and the WSGI server, and why replacing proxy_pass with uwsgi_pass would not work against that HTTP server. Continue to route ownership.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Node.js and Python backend hosting
Connect independently running applications to Nginx by choosing the protocol, listener and process boundary.
Which process executes a WSGI callable?
What does /api/items become with proxy_pass ending in / inside /api/?
Which directive fits a normal Node HTTP listener?
What does the Memcached module do on a normal cache lookup?
Which Python interface supports asynchronous message-based applications?