Stream subsystem fundamentals
Choose the transport layer
A stream proxy accepts transport sessions and forwards application bytes. HTTP proxying instead parses requests and can select a destination based on a path or header. Use stream for a custom TCP protocol or a UDP service; use HTTP for a web API needing path routing. A TCP connection has a lifetime and a byte stream, not HTTP request boundaries. A UDP datagram has a message boundary but no TCP-style connection. The diagram shows the two independent frontends in our lab.
TCP client → 127.0.0.1:19110 → TCP echo A or BUDP client → 127.0.0.1:19111 → UDP echo A or BCheck module availability before writing config
The stream subsystem can be built into Nginx or compiled as a loadable module. Check your binary and package inventory. A dynamic build flag does not prove the shared object is installed. In an approved lab, locate the matching package module and verify its ABI; do not download arbitrary .so files. These discovery commands do not start a service.
nginx -vnginx -Vnginx -hUse a separate top-level stream block
The following complete minimal configuration assumes stream is already compiled in or loaded by a reviewed main-context load_module directive. The listener is loopback only; a toy backend must listen on 19112. This configuration forwards bytes, not a URL. HTTP location blocks and HTTP headers are not available here. Test using an isolated prefix with owned logs, not the system config.
worker_processes 1;pid nginx.pid;error_log error.log notice;events { worker_connections 64; }stream { server { listen 127.0.0.1:19110; proxy_pass 127.0.0.1:19112; }}Avoid mixing HTTP and stream contexts
This deliberately invalid fragment puts an HTTP path matcher inside a stream server. For HTTP routes, use an http block and its own listener; for generic TCP, choose fixed upstream endpoints. The two subsystems have similarly named directives with independent contracts.
stream { server { listen 127.0.0.1:19110; # INVALID: location belongs to HTTP location /api/ { proxy_pass http://app; } }}Practice and next steps
Explain why an HTTP path cannot select a stream backend and identify the required module.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Stream subsystem fundamentals
Distinguish TCP/UDP sessions from HTTP requests
Where does stream belong?
What does a generic stream proxy route?
What does --with-stream=dynamic establish?
What is the safer lab listener?
What is a TCP stream?