Nginx Installation
Nginx (pronounced "engine-x") is an event-driven web server and reverse proxy. Unlike Apache's process-per-connection model, Nginx uses asynchronous non-blocking I/O to handle thousands of concurrent connections with very low memory overhead. This makes Nginx the preferred choice for serving static files at high traffic volumes and as a reverse proxy in front of application servers. On Ubuntu, you can install Nginx from the Ubuntu repository (slightly older) or from the official Nginx repository (latest stable).
Nginx architecture
Nginx process model:
Master process (root, reads config, manages workers)
├── Worker 1 (handles thousands of connections via epoll)
├── Worker 2 (usually 1 worker per CPU core)
└── Worker N
vs Apache:
Apache (prefork): 1 connection = 1 process (memory-intensive)
Apache (worker): 1 connection = 1 thread
Nginx: 1 worker = 1000s of connections (event loop)Installing Nginx
# Option 1: Ubuntu repository (easier, slightly older version)
sudo apt update
sudo apt install -y nginx
# Option 2: Official Nginx repository (latest stable)
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
echo "deb http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
sudo apt update && sudo apt install -y nginx
# Verify installation:
nginx -v
systemctl status nginx
curl -I http://localhost
nginx -v output
nginx version: nginx/1.24.0
sudo ufw allow 'Nginx Full' # Allow ports 80 and 443
Configuration structure
# Nginx config layout:
# /etc/nginx/nginx.conf ← main config (global settings)
# /etc/nginx/conf.d/*.conf ← server blocks (load order by name)
# /etc/nginx/sites-available/ ← Ubuntu-style site configs
# /etc/nginx/sites-enabled/ ← symlinks to enabled sites
cat /etc/nginx/nginx.conf
Key sections of nginx.conf
worker_processes auto; # auto = one worker per CPU core
events {
worker_connections 1024; # max connections per worker
}
http {
include /etc/nginx/mime.types;
server_tokens off; # hide version in headers/error pages
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Managing Nginx
# Test configuration syntax (always before reload):
sudo nginx -t
nginx -t output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl reload nginx # Graceful reload (preferred)
sudo systemctl restart nginx # Full restart
# Check error log:
sudo tail -f /var/log/nginx/error.log
Nginx vs Apache: which to choose
| Scenario | Better choice |
|---|---|
| High-traffic static file serving | Nginx |
| Reverse proxy / load balancer | Nginx |
| PHP application (mod_php) | Apache (simpler setup) |
| PHP-FPM application | Either (both work well) |
| .htaccess needed (shared hosting) | Apache |
| Large number of concurrent connections | Nginx |
Conclusion
After installing Nginx, immediately set server_tokens off; in nginx.conf to hide the version string from HTTP headers and error pages. Then create your first server block in /etc/nginx/sites-available/, enable it with a symlink to sites-enabled/, test with nginx -t, and reload. The Nginx documentation is excellent — the official docs at nginx.org explain each directive with context that the Ubuntu manpages lack.
FAQ
Is Nginx Installation important for Ubuntu administrators?+
Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.
Should I practice this on a live server?+
Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.
What should I do after reading this article?+
Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support