NGINX (pronounced “engine-x”) is a high-performance web server and reverse proxy known for its speed, scalability, and low resource usage. Originally developed by Igor Sysoev in 2004 to handle the C10k problem (10,000 concurrent connections), NGINX quickly became a powerhouse used by giants like Netflix, Airbnb, GitHub, and Dropbox.
Whether you're hosting static sites, acting as a load balancer, or managing complex microservices, NGINX does it cleanly and efficiently.
sudo apt update
sudo apt install nginx
sudo systemctl start nginx
sudo systemctl enable nginx
brew install nginx
brew services start nginx
📍 Open http://localhost:8080 or http://localhost and you'll see the NGINX welcome
screen!
/etc/nginx/nginx.conf - main config file/etc/nginx/sites-available/ - available virtual hosts/etc/nginx/sites-enabled/ - active vHosts (symlinked)/var/www/html/ - default public root/etc/nginx/conf.d/ - drop-in configsexample.comserver {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com/public;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_log /var/log/nginx/example.error.log;
access_log /var/log/nginx/example.access.log;
}
Then activate it:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
NGINX is often used to proxy traffic to backend servers (Node.js, Django, Laravel, etc.), handle SSL, and serve static files.
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
This setup routes all traffic from api.example.com to a backend server running locally on port 3000
(e.g. Express, NestJS, Fastify).
Install Certbot and run:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx
That's it — SSL certs auto-configured, and it renews them for you. 🎉
Serving static HTML/CSS/JS? Here's a lean config:
server {
listen 80;
server_name static.example.com;
root /var/www/static-site;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
limit_reqgzip on;
gzip_types text/plain text/css application/json application/javascript;
gzip_min_length 256;
| Feature | NGINX | Apache |
|---|---|---|
| Performance | High (event-based) | Moderate (process-based) |
| Memory Usage | Low | Higher |
| .htaccess Support | No ❌ | Yes ✅ |
| Ease of Setup | Straightforward | Verbose but flexible |
sudo nginx -t # test config
sudo systemctl reload nginx
This ensures zero-downtime reloads, even in production!
Want to distribute load between Node.js servers?
upstream app_cluster {
server 127.0.0.1:3000;
server 127.0.0.1:3001;
}
server {
listen 80;
server_name app.example.com;
location / {
proxy_pass http://app_cluster;
}
}
NGINX is a web server that does much more than just serve files — it's the silent performance monster behind many of the world's top websites. From load balancing and caching to secure HTTPS proxies, NGINX is an essential tool in any modern web stack.
Still using Apache for everything? NGINX might be the upgrade your stack is waiting for. 🚀
— Blog by Aelify (ML2AI.com)
📚 Documentation Index