Understanding Nginx: Core Concepts, Features, and Architecture Explained
This article introduces Nginx as a high‑performance, open‑source HTTP and reverse‑proxy server, explains forward and reverse proxy differences, outlines server types, highlights key features and modules, describes its multi‑process model and request handling, and showcases real‑world deployments.
1. Concept
Nginx (Engine X) is a free, open‑source, high‑performance HTTP server and reverse‑proxy server; it also supports IMAP, POP3, and SMTP proxying, allowing it to host websites directly or act as a reverse proxy.
It solves the C10K problem—handling 10,000 concurrent connections—by using an event‑driven, asynchronous architecture instead of traditional thread‑per‑request models.
Although its market share is modest, its high performance and low memory consumption make it increasingly popular for load‑balancing scenarios, used by sites such as WordPress and GitHub.
2. Forward Proxy vs. Reverse Proxy
A forward proxy sits on the client side, forwarding client requests to external servers (e.g., GoAgent for bypassing firewalls). The client must be configured with the proxy’s IP and port.
A reverse proxy operates on the server side, receiving client requests, forwarding them to backend servers, and returning the responses to clients; Nginx is a classic reverse‑proxy implementation.
Clients see the reverse proxy as the origin server and need no special configuration; the proxy decides where to forward the request and returns the result.
3. Types of Servers
1) Web servers (e.g., Nginx, Apache, IIS) provide HTTP access. 2) Application servers run application code. 3) Proxy servers mediate client access. 4) Reverse proxies. 5) Backend servers. 6) CDN cache servers, which are reverse‑proxy‑based solutions for distant access.
4. Nginx Features
1) Cross‑platform support for Unix‑like systems and Windows. 2) Simple configuration. 3) Non‑blocking, high‑concurrency handling (up to 50,000 concurrent connections in tests, 20‑30k in production). 4) No long‑living connections between Nginx and backend servers. 5) Asynchronous request reception reduces backend load. 6) Simultaneous receiving from backends and sending to clients. 7) Low network dependency; works with simple ping for load balancing. 8) Built‑in health checks based on status codes and timeouts. 9) Master/worker multi‑process model. 10) Low memory usage, cost‑effective, bandwidth‑saving, and high stability.
5. Basic Functions
Nginx offers core HTTP capabilities and extensible modules. Each module provides specific functionality that can be compiled into the server.
Basic HTTP functions
Serve static files and index files, automatic indexing, file descriptor caching.
Cache‑accelerated reverse proxy and FastCGI, simple load balancing and failover.
Modular architecture with filters (gzip, byte‑range, chunked, SSI, etc.).
SSL/TLS and SNI support.
IMAP/POP3 proxy services.
External HTTP authentication for IMAP/POP3 and SMTP backends.
Additional HTTP functions
Name‑based and IP‑based virtual hosting.
Keep‑alive and pipelined connections.
Flexible configuration with online reload without interrupting service.
Customizable access log formats, log rotation, and error‑code redirection.
Rate limiting.
6. Core Modules
The core consists of the CoreModule, EventsModule, and the third‑party HttpCoreModule. CoreModule controls basic server functions, EventsModule manages connection handling, and HttpCoreModule provides essential HTTP access.
7. Internal Process Model
Nginx primarily uses a multi‑process architecture with one master process and multiple worker processes. The master manages workers, handling signals and monitoring status, while workers handle network events independently. The number of workers is typically set to match CPU cores.
8. Request Handling
On startup, Nginx parses its configuration, opens listening sockets, and forks worker processes. Workers compete to accept new connections. Once a connection is accepted, Nginx creates an ngx_connection_t structure, sets read/write event handlers, exchanges data, and finally closes the connection.
9. Real‑World Usage
Originally developed in Russia, Nginx runs on major Russian portals like Rambler Media and powers over 20% of Russian virtual‑hosting platforms.
In China, many large sites—including Taobao, Sina Blog, NetEase News, 56.com, Discuz!, and Douban—use Nginx as a web server or reverse proxy.
Recent projects often combine Nginx with Tomcat to build high‑performance load‑balancing clusters, leveraging Nginx’s reverse‑proxy capabilities.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.