Task 1: Controlling Nginx with systemctl

1. Check the status of Nginx

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.

2. Start Nginx

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.

3. Stop Nginx

Command:

sudo systemctl stop nginx

Explanation: This command stops the Nginx service. It might be necessary before making major configuration changes or when troubleshooting.

4. Restart Nginx

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).

5. Reload Nginx

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.

6. Enable Nginx to start on boot

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.

7. Disable Nginx from starting on boot

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.