What is NGINX
Web server and reverse proxy
NGINX is a high-performance open-source web server, reverse proxy, load balancer, and HTTP cache. Created by Igor Sysoev in 2004, now owned by F5 Networks.
Core Functions
- Web server — serving static content
- Reverse proxy — proxying requests to backend servers
- Load balancing — distributing traffic across servers
- SSL/TLS termination — handling HTTPS connections
- HTTP caching — caching upstream server responses
Advantages
- Asynchronous event-driven architecture
- Low memory consumption
- High performance (10K+ connections)
- Simple configuration
- Modular architecture
Typical Use Cases
- Serving static files (HTML, CSS, JS, images)
- Reverse proxy for Node.js, Python, PHP, Java
- API Gateway
- Load balancing between Docker containers
- SSL offloading for microservices
Basic Configuration
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
}
location /static/ {
root /var/www;
expires 30d;
}
}
NGINX vs Apache
| Parameter | NGINX | Apache | |-----------|-------|--------| | Architecture | Event-driven | Process/Thread | | Static files | Faster | Slower | | .htaccess | No | Yes | | Configuration | Centralized | Distributed |
Popular Modules
- ngx_http_gzip_module — response compression
- ngx_http_ssl_module — HTTPS
- ngx_http_proxy_module — proxying
- ngx_http_upstream_module — load balancing
- ngx_http_rewrite_module — URL rewriting