Nginx, Apache.

ยท

2 min read

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.

ย