Nginx Introduction
What is Nginx
Nginx (pronounced "engine x") is an HTTP web server, reverse proxy, content cache, load balancer, TCP/UDP proxy server, and mail proxy server.
Originally written by Igor Sysoev and distributed under the 2-clause BSD License.
Key Features
Nginx is known for its flexibility and high performance with low resource consumption:
- World's most popular web server
- One of the most popular Docker images
- Powers multiple Ingress Controllers for Kubernetes, including the official Kubernetes Ingress Controller
Basic HTTP Server Features
- Serving static and index files
- Autoindexing capability
- Open file descriptor cache
- Accelerated reverse proxying with caching
- Load balancing and fault tolerance
- Accelerated support with caching of FastCGI, uwsgi, SCGI, and memcached servers
- Modular architecture
- Filters include: gzipping, byte ranges, chunked responses, XSLT, SSI, and image transformation
- SSL and TLS SNI support
- HTTP/2 support with weighted and dependency-based prioritization
- HTTP/3 support
Other HTTP Server Features
- Name-based and IP-based virtual servers
- Keep-alive and pipelined connections support
- Access log formats, buffered log writing, fast log rotation, and syslog logging
- 3xx-5xx error codes redirection
- Rewrite module with URI changing using regular expressions
- Access control based on client IP address, password (HTTP Basic authentication), and subrequest results
- HTTP referer validation
- PUT, DELETE, MKCOL, COPY, and MOVE methods
- FLV and MP4 streaming
- Response rate limiting
- Limiting simultaneous connections or requests from one address
- IP-based geolocation
- A/B testing
- Request mirroring
- Embedded Perl
- njs scripting language
Mail Proxy Server Features
- User redirection to IMAP or POP3 server using external HTTP authentication server
- User authentication using external HTTP authentication server and connection redirection to internal SMTP server
- Authentication methods: POP3 (USER/PASS, APOP, AUTH LOGIN/PLAIN/CRAM-MD5), IMAP (LOGIN, AUTH LOGIN/PLAIN/CRAM-MD5), SMTP (AUTH LOGIN/PLAIN/CRAM-MD5)
- SSL support
- STARTTLS and STLS support
TCP/UDP Proxy Server Features
- Generic proxying of TCP and UDP
- SSL and TLS SNI support for TCP
- Load balancing and fault tolerance
- Access control based on client address
- Limiting simultaneous connections from one address
- Access log formats, buffered log writing, fast log rotation, and syslog logging
- IP-based geolocation
- A/B testing
- njs scripting language
Architecture and Scalability
- One master process and several worker processes
- Worker processes run under an unprivileged user
- Flexible configuration
- Reconfiguration and upgrade of executable without interruption of client servicing
- Support for kqueue (FreeBSD 4.1+), epoll (Linux 2.6+), /dev/poll (Solaris 7 11/99+), event ports (Solaris 10), select, and poll
- Support for various kqueue features including EV_CLEAR, EV_DISABLE, NOTE_LOWAT, EV_EOF, number of available data, error codes
- Support for various epoll features including EPOLLRDHUP (Linux 2.6.17+, glibc 2.8+) and EPOLLEXCLUSIVE (Linux 4.5+, glibc 2.24+)
- sendfile (FreeBSD 3.1+, Linux 2.2+, macOS 10.5+), sendfile64 (Linux 2.4.21+), and sendfilev (Solaris 8 7/01+) support
- File AIO support (FreeBSD 4.3+, Linux 2.6.22+)
- DIRECTIO support (FreeBSD 4.4+, Linux 2.4+, Solaris 2.6+, macOS)
- Accept-filters (FreeBSD 4.1+, NetBSD 5.0+) and TCP_DEFER_ACCEPT support
- 10,000 inactive HTTP keep-alive connections take about 2.5M memory
- Data copy operations are kept to a minimum
Supported Operating Systems and Platforms
- FreeBSD 3 — 12 / i386; FreeBSD 5 — 12 / amd64; FreeBSD 11 / ppc; FreeBSD 12 / ppc64
- Linux 2.2 — 4 / i386; Linux 2.6 — 5 / amd64; Linux 3 — 4 / armv6l, armv7l, aarch64, ppc64le; Linux 4 — 5 / s390x
- Solaris 9 / i386, sun4u; Solaris 10 / i386, amd64, sun4v; Solaris 11 / x86
- AIX 7.1 / powerpc
- HP-UX 11.31 / ia64
- macOS / ppc, i386, x86_64
- Windows XP, Windows Server 2003, Windows 7, Windows 10, Windows 11
Nginx Advantages
High Performance
Nginx uses an event-driven asynchronous non-blocking model, capable of handling high concurrency connections while maintaining low memory usage.
Low Resource Consumption
Compared to other web servers, Nginx consumes significantly less memory and CPU under the same concurrency levels.
High Stability
Nginx's stability has been proven by millions of websites worldwide, with extremely rare crashes.
Simple Configuration
Nginx configuration files are concise and easy to understand.
Strong Extensibility
Supports rich modules, allowing enabling or disabling functions as needed.
Hot Deployment
Reload configuration and upgrade versions without interrupting service.
Application Scenarios
Nginx is widely used in the following scenarios:
- Web Server: As an HTTP server for static files
- Reverse Proxy: As a reverse proxy for backend servers
- Load Balancer: As a load balancer for multiple backend servers
- Cache Server: As a CDN or internal cache server
- API Gateway: As an entry gateway for microservices
- Mail Proxy: As POP3, IMAP, and SMTP proxy
- TCP/UDP Proxy: As a proxy for TCP and UDP protocols
Commercial Support
Enterprise distributions, commercial support, and training are available from F5, Inc.
