Nginx
Nginx is an open-source web server and reverse proxy that handles HTTP, HTTPS, and mail protocols with high concurrency and low memory usage.
Nginx is an open-source web server and reverse proxy server that handles HTTP, HTTPS, SMTP, POP3, and IMAP protocols on Linux, macOS, and BSD systems.
What Nginx Does and When to Use It
The Nginx web server processes incoming client requests and serves static content such as HTML, CSS, JavaScript, and images. Nginx also functions as a reverse proxy, forwarding requests to backend application servers like PHP-FPM, Node.js, or Python WSGI. It handles SSL/TLS termination, load balancing, and HTTP caching.
Nginx uses an asynchronous, event-driven architecture that handles thousands of concurrent connections with minimal memory. This design makes Nginx a common choice for high-traffic websites, API gateways, and microservice architectures. Apache HTTP Server uses a process-per-connection model that consumes more memory under high concurrency.
Use Nginx when the deployment requires a reverse proxy, a load balancer, or a high-performance static file server. Nginx is not a general-purpose application server -- it delegates dynamic content processing to upstream services such as PHP-FPM or Gunicorn.
Core Concepts of Nginx
Nginx Server Blocks (Virtual Hosts)
Nginx uses server blocks to host multiple domains on a single machine. Each server block defines a
server_name, a
listen port, and a document root. Server blocks in Nginx serve the same purpose as VirtualHost entries in Apache HTTP Server.
Nginx Location Blocks and Request Routing
Nginx evaluates location blocks inside each server block to determine how to handle a specific URI. Location blocks match requests using exact strings, prefixes, or regular expressions. Each location block can define its own root directory, proxy destination, or access rules.
Nginx as a Reverse Proxy
Nginx forwards client requests to upstream backend servers using the
proxy_pass directive. The reverse proxy configuration supports load balancing across multiple backends, connection pooling, and request buffering. Nginx sits between clients and application servers, handling SSL termination and caching at the edge.
Common Configuration Tasks
The primary configuration file for Nginx is
nginx.conf. All server blocks, location blocks, and global directives reside in this file or in files it includes. See the
nginx.conf articlefor a full reference of the configuration file structure, directives, and contexts.
Related Tools
PHP-FPM (FastCGI Process Manager) is the most common upstream backend for Nginx when serving PHP applications. Nginx communicates with PHP-FPM through a Unix socket or TCP connection using the
fastcgi_pass directive. See the
nginx.conf troubleshooting sectionfor errors related to PHP-FPM integration.