sudo systemctl start nginx
: Start Nginx servicesudo systemctl stop nginx
: Stop Nginx servicesudo systemctl restart nginx
: Restart Nginx servicesudo systemctl reload nginx
: Reload Nginx configuration without stopping the servicesudo systemctl status nginx
: Check the status of Nginx servicesudo systemctl enable nginx
: Enable Nginx to start on bootsudo systemctl disable nginx
: Disable Nginx from starting on bootsudo systemctl is-enabled nginx
: Check if Nginx is set to start on bootsudo systemctl mask nginx
: Completely disable the Nginx servicesudo systemctl unmask nginx
: Remove a mask from the Nginx servicesudo nginx -t
: Test Nginx configuration for syntax errorssudo nginx -T
: Test Nginx configuration and print itsudo nginx -s reload
: Reload Nginx configuration (alternative to systemctl reload)sudo nginx -s reopen
: Reopen log filessudo nginx -c /path/to/nginx.conf
: Start Nginx with a specific configuration filesudo nginx -s stop
: Stop Nginx processes quicklysudo nginx -s quit
: Stop Nginx processes gracefullysudo nginx -s reopen
: Reopen log filessudo nginx
: Start Nginx if it’s not runningsudo kill -HUP $(cat /var/run/nginx.pid)
: Send HUP signal to reload configurationsudo apt update
: Update package lists (for Ubuntu/Debian)sudo apt install nginx
: Install Nginx (for Ubuntu/Debian)sudo apt upgrade nginx
: Upgrade Nginx to the latest version (for Ubuntu/Debian)sudo apt remove nginx
: Remove Nginx but keep configuration filessudo apt purge nginx
: Remove Nginx and all its configuration filestail -f /var/log/nginx/access.log
: View real-time access logstail -f /var/log/nginx/error.log
: View real-time error logsgrep "pattern" /var/log/nginx/access.log
: Search for a pattern in access logssudo nginx -g "error_log /var/log/nginx/error.log debug;"
: Start Nginx with debug-level error logging/etc/nginx/nginx.conf
: Main Nginx configuration file/etc/nginx/sites-available/
: Directory for server block files/etc/nginx/sites-enabled/
: Directory for enabled server blocks/var/www/html/
: Default web content directory/var/log/nginx/
: Directory for Nginx log filesps aux | grep nginx
: Check running Nginx processesnetstat -tlpn | grep nginx
: Check which ports Nginx is listening onsudo lsof -i :80
: Check what’s using port 80 (default HTTP port)sudo nginx -V
: Show Nginx version and configuration optionssudo nginx -v
: Show Nginx versionsudo nginx -h
: Show Nginx help messagesudo journalctl -u nginx
: View Nginx service logssudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt
: Generate a self-signed SSL certificatesudo nginx -t -c /etc/nginx/nginx.conf
: Test SSL configurationsudo nginx -s reload
: Reload configuration without downtimeulimit -n
: Check the current limit on open filessudo sysctl -w net.core.somaxconn=65535
: Increase the maximum number of concurrent connectionsRemember to use sudo
with these commands as Nginx operations often require root privileges.