Skip to main content

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:

  1. Static file delivery — HTML, CSS, JS, images served directly from disk with minimal overhead
  2. Reverse proxy — sitting in front of Node.js, Python, Go, or PHP-FPM apps
  3. Load balancing — distributing requests across multiple upstream servers
  4. SSL termination — handling TLS so backend apps don't have to
  5. API gateway — rate limiting, auth, routing before the backend

Nginx vs. Apache vs. OpenLiteSpeed​

FeatureNginxApacheOpenLiteSpeed
ArchitectureEvent-drivenPrefork (MPM)Event-driven
Config styleBlocks/directives.htaccess compatibleBlocks (similar to Nginx)
Static filesExcellentGoodExcellent
PHP executionVia PHP-FPM onlymod_php or PHP-FPMVia LSAPI (fastest)
Reverse proxyExcellent, first-classGood (mod_proxy)Good
.htaccess supportNo (by design)YesPartial
Memory usageVery lowHigher (prefork)Low
Config reloadGraceful (zero downtime)GracefulGraceful
WebAdmin GUINoNoYes
HTTP/3 QUICYes (1.25+)ExperimentalYes
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 .htaccess files 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​

ComponentWhat It Is
nginx (open source)Free, community-maintained, most widely used
nginx PlusCommercial, adds health checks, dashboard, JWT auth, etc.
OpenrestyNginx + LuaJIT — scripting inside Nginx for dynamic behavior
TengineAlibaba's fork with extra modules
UnitNginx'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​

ConceptWhat It Means
Master processReads config, manages worker processes. Runs as root.
Worker processHandles actual connections. Runs as www-data / nginx.
Event loopOne worker handles thousands of connections without blocking
Server blockConfig unit for one site (like Apache VirtualHost)
Location blockURL pattern rules inside a server block
upstreamPool 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​

PitfallWhat happensFix
Editing config without reloadingChanges not appliedsudo nginx -s reload after every edit
Not running nginx -t firstReload breaks with syntax errorAlways test syntax before reloading
Wrong socket path for PHP-FPM502 Bad Gatewayls /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.