Nginx is a lightweight, high-performance web server. This guide shows you how to install it on Ubuntu or Debian.
Step 1: Update your package manager
Before installing anything, refresh your package lists:
sudo apt update
Step 2: Install Nginx
Install the Nginx package:
sudo apt install -y nginx
On RHEL/CentOS, use dnf install nginx instead.
Step 3: Start and enable Nginx
Start the service:
sudo systemctl start nginx
Enable it to start automatically on boot:
sudo systemctl enable nginx
Step 4: Verify Nginx is running
Check the status:
sudo systemctl status nginx
You should see active (running).
Step 5: Test in your browser
Open your browser and visit http://your-server-ip. You should see the Nginx welcome page.
If you can't reach it, check your firewall or security group:
sudo ufw allow 'Nginx Full'
sudo ufw enable
(If ufw is not installed, use your cloud provider's security group settings instead.)
Common commands
Reload Nginx after config changes (without stopping traffic):
sudo systemctl reload nginx
Restart Nginx:
sudo systemctl restart nginx
Stop Nginx:
sudo systemctl stop nginx
Check the configuration for syntax errors:
sudo nginx -t
Tips
- Nginx configuration files are in
/etc/nginx/ - The main config is
/etc/nginx/nginx.conf - Individual site configs go in
/etc/nginx/sites-available/ - Create a server block (virtual host) to point Nginx to your website files