A strong server program called Nginx is used to direct network traffic. Although it may be set up as an average web server, it is frequently used as a reverse proxy server. How do Start, Stop, and Restart Nginx? Web server is one of the most frequent procedures you will experience.
Learn How to Start, Stop, and Restart Nginx? service in this lesson:
- A machine with Nginx installed and set up
- Access to a command line or terminal window
- A user account with root or sudo access
- If operating remotely, an active SSH connection to a distant system
Using systemctl, start, stop, and restart Nginx
How to Check Your Nginx Server’s Status? On your server, Nginx is active as a service. This means that even if nothing is visible on the screen, it should be running actively in the background. Enter the following command in a terminal window to view the Nginx service’s status:
systemctl status nginx with sudo
The system will enter a status mode and present a wealth of data regarding the Nginx service.
- The third line will display a green active (running) status if the service is active.
- Nginx will appear inactive in plain white if it is not running.
- You will notice a red status failed along with additional information if Nginx was unable to load due to an error.
To bring up the bash prompt once more, press q.
On contemporary Linux distributions (Ubuntu 20.04/18.04. /16.04, CentOS 7/7, and Debian 9/10), SystemD is the default service manager. The systemctl command controls how the SystemD manager works.
How do Start, Stop, and Restart Nginx? A fundamental Linux command is called systemctl. As a result, it can be applied to any Linux service.
Turn off and on Nginx
The Nginx service can be started and stopped using systemctl.
Run the following command to terminate Nginx:
systemctl sudo stop nginx
Use the systemctl command with the start option to start Nginx:
systemctl start nginx sudo
How to Start Nginx Again?
Restart Nginx politely. After modifying the settings, it’s best to gently reload the service while refreshing Nginx. With the new setup, new processes are started and old ones are terminated.
Reload the Nginx service on a Linux system by using the systemctl command. Run the command line:
systemctl reload nginx with sudo
Force Nginx to Start Up
You can force a complete restart of Nginx to apply significant configuration changes. This restarts the entire package while forcing the shutdown of the service and all of its child processes.
How do Start, Stop, and Restart Nginx? type the upcoming command:
restart nginx with sudo systemctl
Restart vs Reload Nginx
Reloading new configuration files allows the Nginx server to continue operating. The server continues to run on the basis of the old configuration files if Nginx detects a syntax mistake in any of the configuration files. Restarting Nginx is riskier than reloading.
Restarting the server will turn off all associated services and turn it back on. Nginx should only be restarted when making significant configuration changes, like switching ports or interfaces. All worker processes will be abruptly terminated by this command.
Setup Nginx to Run Upon Boot
To activate Nginx, use the systemctl command’s enable option:
systemctl sudo enable nginx
To disable Nginx, use the systemctl command with the disable option:
systemctl disable nginx sudo
Start, Stop, and Reload Nginx with the Nginx Command
The Nginx command can be used to access a collection of integrated tools that Nginx has built-in for administering the service.
1: Nginx Launch
Enter the following to launch Nginx and associated processes:
/etc/init. d/nginx start with sudo
The following will appear in the terminal output if the command was successful:
[Good] Launching nginx (using systemctl): Nginx.Service
2: Nginx Restart
Nginx and associated processes should be forcibly closed and restarted:
/etc/init. d/nginx restart with sudo
How do Start, Stop, and Restart Nginx? Use the nginx -s command as an alternative:
restart nginx with sudo
3: Nginx Stop
The Nginx service can be stopped or disabled by entering the following:
/etc/init. d/nginx stop with sudo
Use the nginx stop command to terminate the Nginx service. Alternately, employ:
nginx -s stop sudo
4: Nginx Reload
Use the following command to gracefully stop and restart Nginx and associated processes:
/etc/init. d/nginx reload with sudo
As an alternative, you can give Nginx direct instructions by using the nginx -s command:
nginx -s sudo reload
5: Nginx Quit
Use the quit command along with the nginx -s command to force-quit the Nginx service:
nginx -s sudo quit
Several techniques for How do Start, Stop, and Restart Nginx? on your server have been covered in this article. When operating an Nginx web server, use these commands for the tasks that are performed most frequently.