Command:
sudo systemctl status nginx
Explanation: This command shows whether Nginx is currently running, its process ID, and some recent log entries. Observe the output and understand what it means when Nginx is active, inactive, or failed.
Command:
sudo systemctl start nginx
Explanation: This command will start Nginx if it isn’t running. It is typically used after a server reboot or after Nginx has been stopped.
Command:
sudo systemctl stop nginx
Explanation: This command stops the Nginx service. It might be necessary before making major configuration changes or when troubleshooting.
Command:
sudo systemctl restart nginx
Explanation: The restart command stops and then starts Nginx. It's useful after configuration changes that require a full service reload. Compare this with the reload command (discussed next).
Command:
sudo systemctl reload nginx
Explanation: Reloading Nginx reloads the configuration without stopping the service, which means ongoing connections are not interrupted. It is crucial to reload rather than restart when making configuration changes that don't require stopping Nginx.
Command:
sudo systemctl enable nginx
Explanation: This ensures that Nginx starts automatically whenever the server reboots. The importance of this setting for a web server that needs to be highly available should be noted.
Command:
sudo systemctl disable nginx
Explanation: Disabling auto-start might be useful in a development environment where Nginx should only run when explicitly started by the user.