
Compare tls termination and tls passthrough in Nginx, explaining when to decrypt at the edge, maintain end-to-end encryption, and the implications for caching and certificates.
Explore NGINX internal architecture, from the master process to worker processes, tuned to CPU cores and hardware threads, handling connections via kernel queues and CPU‑bound versus IO‑bound tasks.
Spin up an nginx web server container with Docker, expose port 80, set a hostname, map a host html folder via volumes, and test serving static pages with curl.
Create two nginx containers on one docker network with identical config, expose ports 80 and 81, and test hostname-based routing to backends; introduces iptables load balancing concepts.
Explore docker networking by spinning up containers on the bridge, inspecting networks, and building custom networks with a gateway to connect isolated containers; learn DNS and IP routing basics.
Syntax:
client_header_timeout time;
Default:
client_header_timeout 60s;
Context:
http, server
Defines a timeout for reading client request header. If a client does not transmit the entire header within this time, the request is terminated with the 408 (Request Time-out) error.
Syntax:
client_body_timeout time;
Default:
client_body_timeout 60s;
Context:
http, server, location
Defines a timeout for reading client request body. The timeout is set only for a period between two successive read operations, not for the transmission of the whole request body. If a client does not transmit anything within this time, the request is terminated with the 408 (Request Time-out) error.
Syntax:
send_timeout time;
Default:
send_timeout 60s;
Context:
http, server, location
Sets a timeout for transmitting a response to the client. The timeout is set only between two successive write operations, not for the transmission of the whole response. If the client does not receive anything within this time, the connection is closed.
Syntax:
keepalive_timeout timeout [header_timeout];
Default:
keepalive_timeout 75s;
Context:
http, server, location
The first parameter sets a timeout during which a keep-alive client connection will stay open on the server side. The zero value disables keep-alive client connections. The optional second parameter sets a value in the “Keep-Alive: timeout=time” response header field. Two parameters may differ.
The “Keep-Alive: timeout=time” header field is recognized by Mozilla and Konqueror. MSIE closes keep-alive connections by itself in about 60 seconds.
Syntax:
lingering_timeout time;
Default:
lingering_timeout 5s;
Context:
http, server, location
When lingering_close is in effect, this directive specifies the maximum waiting time for more client data to arrive. If data are not received during this time, the connection is closed. Otherwise, the data are read and ignored, and nginx starts waiting for more data again. The “wait-read-ignore” cycle is repeated, but no longer than specified by the lingering_time directive.
Syntax:
resolver_timeout time;
Default:
resolver_timeout 30s;
Context:
http, server, location
Sets a timeout for name resolution, for example:
resolver_timeout 5s;
Syntax:
proxy_connect_timeout time;
Default:
proxy_connect_timeout 60s;
Context:
http, server, location
Defines a timeout for establishing a connection with a proxied server. It should be noted that this timeout cannot usually exceed 75 seconds.
Syntax:
proxy_send_timeout time;
Default:
proxy_send_timeout 60s;
Context:
http, server, location
Sets a timeout for transmitting a request to the proxied server. The timeout is set only between two successive write operations, not for the transmission of the whole request. If the proxied server does not receive anything within this time, the connection is closed.
Syntax:
proxy_read_timeout time;
Default:
proxy_read_timeout 60s;
Context:
http, server, location
Defines a timeout for reading a response from the proxied server. The timeout is set only between two successive read operations, not for the transmission of the whole response. If the proxied server does not transmit anything within this time, the connection is closed.
Syntax:
proxy_next_upstream_timeout time;
Default:
proxy_next_upstream_timeout 0;
Context:
http, server, location
This directive appeared in version 1.7.5.
Limits the time during which a request can be passed to the next server. The 0 value turns off this limitation.
Syntax:
keepalive_timeout timeout;
Default:
keepalive_timeout 60s;
Context:
upstream
This directive appeared in version 1.15.3.
Sets a timeout during which an idle keepalive connection to an upstream server will stay open.
Find the code here https://github.com/hnasr/javascript_playground/tree/master/docker
install nginx and configure it as a layer seven reverse proxy to balance dockerized nodejs services, explore layer four proxy, and enable https tls 1.3 with letsencrypt and http2.
Install nginx on macOS using Homebrew and brew install nginx, then delete the default configuration file and start from scratch.
Configure Nginx as a layer seven http proxy to load balance four NodeJS services with upstream blocks and round-robin, using proxy_pass and ip_hash sticky sessions.
Enable https on nginx by configuring port 80 and 443, obtaining a Let's Encrypt certificate with certbot standalone, and loading the public and private keys into the nginx config.
Discover how to scale websocket connections with nginx, building a NodeJS websocket server, and compare layer four and layer seven proxying within the OSI framework.
Compare layer four websockets proxying, highlighting end-to-end tunneling for layer four versus content-aware TLS termination and smart routing at layer seven.
Spin up a websocket server with nodejs and an http server, handle upgrade requests, and load balance multiple websocket backends with nginx, testing across dynamic ports.
Configure nginx as a layer 4 websocket proxy on port 80, tunneling all tcp connections to websocket backends. Employ blind proxying with round-robin load balancing, where paths do not matter.
Configure NGINX as a layer 7 WebSocket proxy and load balancer by routing /app and /chat to backend websockets, handling upgrade headers, and serving an index page for testing.
Explore WebSockets fundamentals, compare layer four and layer seven proxying, spin up a websocket server, then deploy Nginx as layer four load balancer and layer seven websocket server.
Explore how to scale NGINX through horizontal scaling, multiple NGINX instances, and load-balancing strategies, including DNS-based resolution and virtual IP with VRP for active-passive failover.
Assess how many backends nginx needs based on workload and connection type; use dedicated web socket connections to avoid layer4 load balancing issues.
Explore the difference between proxy and reverse proxy, their use cases in caching, anonymity, and blocking, and how microservices rely on sidecar proxies, ingress, and load balancing.
Cloudflare moves from nginx to pangora, addressing worker process limits and backend connection pools by sharing threads and pools to reduce handshakes and support http upstream.
NGINX is an open-source web server written in C and can also be used as a reverse proxy and a load balancer. This class Is an introduction to NGINX, by the end of this class you will be able to understand the fundamentals of NGINX and spin up your own instance and even secure it with a legitimate certificate.
Here are the topics that I will discuss:
What is NGINX?
NGINX Use Cases
Layer 4 and Layer 7 Proxying in Nginx
NGINX Timoouts
Example
Install Nginx (mac)
Nginx as a Web Server
Static content
Regular expression in NGINX
proxy_pass
Nginx as a Layer 7 Proxy
Proxy to 4 backend NodeJS services (docker)
IP_Hash load balancing
Split load to multiple backends (app1/app2)
Block certain requests (/admin)
NGINX as a Layer 4 Proxy
Create DNS record
Enable HTTPS on NGINX (lets encrypt)
Enable TLS 1.3 on NGINX
Enable HTTP/2 on NGINX
A small blurb about NGINX
NGINX is one of a handful of servers written to address the C10K problem. Unlike traditional servers, NGINX doesn’t rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. This architecture uses small, but more importantly, predictable amounts of memory under load. Even if you don’t expect to handle thousands of simultaneous requests, you can still benefit from NGINX’s high-performance and small memory footprint. NGINX scales in all directions: from the smallest VPS all the way up to large clusters of servers.