July 12, 2025

Essential Nginx Commands Every Server Admin Should Know

Whether you’re hosting a static website, running a Node.js app, or reverse-proxying APIs, Nginx is one of the most powerful and efficient web servers in the world. For Ubuntu-based servers, knowing a handful of commands can save hours of debugging and downtime.

In this article, Prism ICT walks you through must-know Nginx commands and maintenance tips for real-world server management.

🧭 1. Check Nginx Status

Command:

sudo systemctl status nginx
  • Displays whether Nginx is running, inactive, or failed.
  • Also shows uptime, logs, and any recent service errors.

πŸ”„ 2. Start, Stop, Restart & Reload Nginx

ActionCommand
Start Nginxsudo systemctl start nginx
Stop Nginxsudo systemctl stop nginx
Restart Nginxsudo systemctl restart nginx
Reload (no downtime)sudo systemctl reload nginx
  • Use reload to apply config changes without dropping active connections.

πŸ› οΈ 3. Test Nginx Configuration

Command:

sudo nginx -t
  • This is crucial before reloading or restarting Nginx.
  • It checks for syntax errors and displays where the config is loaded from.

πŸ“‚ 4. Nginx Config File Paths

PurposePath
Main Config/etc/nginx/nginx.conf
Site Configs (enabled)/etc/nginx/sites-enabled/
Site Configs (available)/etc/nginx/sites-available/
Default Web Root/var/www/html/

πŸ’‘ Best practice: create virtual host files in sites-available/ and link them using:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

πŸ” 5. View Nginx Access & Error Logs

Log TypeCommand
Access Logssudo tail -f /var/log/nginx/access.log
Error Logssudo tail -f /var/log/nginx/error.log

Use -n 100 to see last 100 lines, or less to scroll easily.

🌐 6. Check Active Listening Ports

Command:

sudo ss -tuln | grep nginx
  • Shows the ports Nginx is actively listening on (e.g., 80, 443).

πŸ” 7. Enable SSL with Let’s Encrypt (Certbot)

Step 1: Install Certbot

sudo apt install certbot python3-certbot-nginx

Step 2: Issue a Certificate

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Step 3: Auto-Renew SSL

sudo certbot renew --dry-run

πŸ“¦ 8. Install or Remove Nginx

Install:

sudo apt update
sudo apt install nginx

Remove:

sudo apt remove nginx

πŸ” 9. Set Nginx to Auto Start on Boot

Enable auto-start:

sudo systemctl enable nginx

Disable auto-start:

sudo systemctl disable nginx

🚧 10. Common Issues & Fixes

IssueFix
Port already in useCheck with sudo lsof -i :80 or :443
Config test failedRun sudo nginx -t and fix file paths or syntax
403 ForbiddenCheck file permissions in /var/www/

🚧 11. Add a new site on nginx

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

🚧 12. Remove /unlink a site on nginx

sudo unlink /etc/nginx/sites-enabled/example.com
sudo nginx -t
sudo systemctl restart nginx

βœ… Final Tips from Prism ICT

  • Always test your config with nginx -t before restarting the server.
  • Use reload over restart for production environments.
  • Keep an eye on logs to catch issues early.
  • Backup config files before making major changes.

πŸ’¬ Need Help Managing Your Nginx Server?
At Prism ICT, we help businesses deploy, scale, and secure their web applications using industry best practices. Whether it’s performance optimization, SSL setup, or reverse proxy configuration β€” we’ve got your back.