What is Nginx
Learning Focus
Leave this lesson with a working understanding of what is nginx that you can apply immediately in production.
Nginx (pronounced "engine-x") is a high-performance web server, reverse proxy, load balancer, and HTTP cache. It was created by Igor Sysoev in 2004 to solve the C10K problem — handling 10,000 simultaneous connections on a single server.
What Nginx Does Best
Nginx excels when you need:
- Static file delivery — HTML, CSS, JS, images served directly from disk with minimal overhead
- Reverse proxy — sitting in front of Node.js, Python, Go, or PHP-FPM apps
- Load balancing — distributing requests across multiple upstream servers
- SSL termination — handling TLS so backend apps don't have to
- API gateway — rate limiting, auth, routing before the backend
Nginx vs. Apache vs. OpenLiteSpeed
| Feature | Nginx | Apache | OpenLiteSpeed |
|---|---|---|---|
| Architecture | Event-driven | Prefork (MPM) | Event-driven |
| Config style | Blocks/directives | .htaccess compatible | Blocks (similar to Nginx) |
| Static files | Excellent | Good | Excellent |
| PHP execution | Via PHP-FPM only | mod_php or PHP-FPM | Via LSAPI (fastest) |
| Reverse proxy | Excellent, first-class | Good (mod_proxy) | Good |
| .htaccess support | No (by design) | Yes | Partial |
| Memory usage | Very low | Higher (prefork) | Low |
| Config reload | Graceful (zero downtime) | Graceful | Graceful |
| WebAdmin GUI | No | No | Yes |
| HTTP/3 QUIC | Yes (1.25+) | Experimental | Yes |
When to Choose Nginx
- You need a reverse proxy or load balancer
- You are serving a Node.js / Python / Go app behind a proxy
- You want very low memory usage for a static site
- You are comfortable editing config files directly (no GUI)
- You need clean, fast SSL termination
When Nginx Is Not the Best Choice
- You have legacy
.htaccessfiles that must work as-is → Apache - You want a built-in WebAdmin GUI → OpenLiteSpeed
- You want the fastest possible PHP execution with LSAPI → OpenLiteSpeed
The Nginx Ecosystem
| Component | What It Is |
|---|---|
| nginx (open source) | Free, community-maintained, most widely used |
| nginx Plus | Commercial, adds health checks, dashboard, JWT auth, etc. |
| Openresty | Nginx + LuaJIT — scripting inside Nginx for dynamic behavior |
| Tengine | Alibaba's fork with extra modules |
| Unit | Nginx's newer application server (not a drop-in replacement) |
For most self-managed VPS setups, nginx open source is the right choice.
Key Concepts to Understand
| Concept | What It Means |
|---|---|
| Master process | Reads config, manages worker processes. Runs as root. |
| Worker process | Handles actual connections. Runs as www-data / nginx. |
| Event loop | One worker handles thousands of connections without blocking |
| Server block | Config unit for one site (like Apache VirtualHost) |
| Location block | URL pattern rules inside a server block |
| upstream | Pool of backend servers that Nginx proxies to |
Hands-On Practice
# Verify Nginx is running
sudo systemctl status nginx
# Test config syntax
sudo nginx -t
# Reload without downtime
sudo nginx -s reload
# Check error log
sudo tail -20 /var/log/nginx/error.log
Common Pitfalls
| Pitfall | What happens | Fix |
|---|---|---|
| Editing config without reloading | Changes not applied | sudo nginx -s reload after every edit |
Not running nginx -t first | Reload breaks with syntax error | Always test syntax before reloading |
| Wrong socket path for PHP-FPM | 502 Bad Gateway | ls /run/php/ and verify the exact socket filename |
What's Next
- Continue to the next lesson in this module, or go to the module index for an overview.
- Use the Cheatsheets for quick CLI reference.