Nginx, Apache.
Nginx (pronounced "engine-x") ->
- Web Server
- Reverse Proxy
- Load Balancer
It is free & open-source.
It's renowned for its efficiency, stability and ability to handle massive loads concurrently.
๐๐ง๐๐๐ซ ๐ญ๐ก๐ ๐ก๐จ๐จ๐ -
Nginx utilizes a non-blocking I/O model, handling multiple client connections simultaneously without creating separate threads for each.
This eliminates the overhead of thread creation and context switching, maximizing resource utilization.
Nginx uses an event-driven approach.
It efficiently waits for events (like incoming connections or data arrival) to occur and triggers specific handler functions to process them.
This avoids wasting CPU cycles on waiting for I/O operations to complete.
Where possible, Nginx uses non-blocking I/O.
So, if it needs to fetch something from disk or a backend server, it initiates the request and then the thread can service other things while that slow operation is pending.
๐๐๐ฌ๐ญ๐๐ซ & ๐๐จ๐ซ๐ค๐๐ซ ๐๐ซ๐จ๐๐๐ฌ๐ฌ๐๐ฌ -
The master process oversees the overall health of Nginx.
It manages worker processes, gracefully restarts them when needed and handles configuration changes.
On the other hand,
Multiple worker processes handle actual client requests and interact with backend servers.
This separation allows Nginx to handle numerous concurrent connections efficiently.
Remember,
Nginx strikes a balance between both approaches -
# Worker Processes (Multi-Process)
# Event-Driven Within Each Process (Not Multi-Threaded)
(Inside each worker process, the event-driven, non-blocking model comes into play.)
๐๐๐ฒ ๐ ๐ฎ๐ง๐๐ญ๐ข๐จ๐ง๐๐ฅ๐ข๐ญ๐ข๐๐ฌ -
# Web Serving
Nginx serves static content (HTML, CSS, images) efficiently.
# Reverse Proxy
Nginx forwards requests to backend servers while potentially adding security or caching functionalities.
Can handle SSL/TLS termination (encryption/decryption).
# Load Balancer (Layer 4 & 7)
Nginx can distribute traffic across multiple backend servers using various algorithms (round-robin, least connections, etc.)
Improves scalability and high availability.