Nginx HTTP Server Installation
This guide covers the essential steps to install and start Nginx on Debian/Ubuntu and CentOS systems.
Installation Steps
- Debian/Ubuntu
- CentOS
1. Update Package Index
sudo apt update
2. Install Nginx
sudo apt install nginx -y
3. Start and Enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
4. Check Status
sudo systemctl status nginx
5. Allow HTTP/HTTPS in Firewall (if UFW is enabled)
sudo ufw allow 'Nginx Full'
6. Test in Browser
Visit: http://localhost or your server's IP address.
1. Update Package Index
sudo yum update -y
2. Install Nginx
sudo yum install nginx -y
3. Start and Enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
4. Check Status
sudo systemctl status nginx
5. Allow HTTP/HTTPS in Firewall (if firewalld is enabled)
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
6. Test in Browser
Visit: http://localhost or your server's IP address.
Uninstall Nginx
- Debian/Ubuntu
- CentOS
sudo apt remove --purge nginx nginx-common -y
sudo apt autoremove -y
sudo yum remove nginx -y
Quick Commands Reference
- Debian/Ubuntu
- CentOS
| Task | Command |
|---|---|
| Start Nginx | sudo systemctl start nginx |
| Stop Nginx | sudo systemctl stop nginx |
| Restart Nginx | sudo systemctl restart nginx |
| Enable on Boot | sudo systemctl enable nginx |
| Status | sudo systemctl status nginx |
| Test Config | sudo nginx -t |
| Task | Command |
|---|---|
| Start Nginx | sudo systemctl start nginx |
| Stop Nginx | sudo systemctl stop nginx |
| Restart Nginx | sudo systemctl restart nginx |
| Enable on Boot | sudo systemctl enable nginx |
| Status | sudo systemctl status nginx |
| Test Config | sudo nginx -t |
Tip: Default web root is /var/www/html.