Introduction
A quick, dependable, open-source, and cost-free web server is Nginx. Being a load balancer, proxy server, and additionally, mail proxy, start Nginx can get configured for use.
Several typical operations get carried out when working with any server. This covers the server’s launch, shutdown, and restart Nginx.
Managing these tasks on Linux for the Nginx server will be covered in this article. The Nginx web server’s starting, stopping, and restarting are some of the most frequent activities you’ll experience. The Nginx service can be started, stopped, and restarted using the instructions in this guide.
System Requirements
The system needs the following to understand its fundamentals:
- a system that has Nginx installed and set up
- the ability to use a terminal window and command line
- an individual account with root or sudo rights
- In the scenario that you’re working remotely, an active SSH connection to a distant system
Start, Stop and Restart Nginx using systemctl
The Best Way to Check Your Nginx Server’s Status
Your server is running Nginx as a service. If nothing appears on the screen, it should still function actively in the background. The following command can be entered in a terminal window to show the current state of the start Nginx service:
- sudo systemctl status nginx
An extensive amount of data about the Nginx service will be displayed once the system enters a status mode.
- The third line will display a green functional (running) status when the service is operational (running).
- When Nginx is not functioning, it will seem inactive in plain white.
- You’ll notice a red status failed with details about the problem whenever something went incorrect and Nginx couldn’t load.
Reopen the bash prompt by pressing Q.
Current Linux distributions, including Ubuntu and CentOS as well as Debian, all come standard with SystemD as their service manager. Utilizing the systemctl command, your SystemD manager operates.
Among the fundamental Linux commands is systemctl. In other words, it can be applied to any Linux service.
Also Read: 50+ Linux Commands with Screenshots (Download PDF)
Turn off and on Nginx
Starting and stopping the Nginx service is possible via systemctl.
Use the following command to stop Nginx:
- sudo systemctl stop nginx
Turn on Nginx by using the systemctl command using the start Nginx option:
- sudo systemctl start nginx
Steps for Restarting Nginx
Restart Nginx considerately
It’s advisable to gently reload the service when refreshing Nginx following configuration changes. The updated configuration ends existing processes and begins new ones.
To relaunch the Nginx service on Linux, execute the systemctl command. Enter the command below:
- sudo systemctl reload nginx
Reloading Nginx is not possible when the Nginx services are not running.
Forcing Nginx to Restart
You can force Nginx to relaunch entirely when making significant configuration updates. The entire service and its dependent processes get forced to end, and the entire application gets restarted.
Execute the command as follows:
- sudo systemctl restart nginx
Nginx: Restart compared to Reload
The reload command allows the Nginx server to continue operating while reloading modified configuration files. Any configuration file reload gets stopped if Nginx detects a syntax issue and the server continues to operate using the previous configuration files. Compared to restarting Nginx, reloading is more secure.
Restarting the server will turn off all associated services as well as the server itself. If you’re changing ports and interfaces, for example, you should only restart Nginx after performing important configuration changes. Using this command will end all worker processes forcibly.
Create a boot configuration for Nginx
When using the systemctl command, utilize the enable option to turn on Nginx.
- sudo systemctl enable nginx
When using the systemctl command, employ the disable option to turn off Nginx.
- sudo systemctl disable nginx
Start, Stop and Restart Nginx using the Command Line
The Nginx command provides access to the collection of integrated management tools that Nginx provides for the service.
Nginx Startup
Input the following information to launch Nginx and related services:
- sudo /etc/init.d/nginx start
The terminal window output is going to display the following when the operation is successful:
The output
- [ ok ] Starting nginx (via systemctl): nginx.service.
Restarting Nginx
To forcefully terminate and relaunch Nginx and associated processes:
- sudo /etc/init.d/nginx restart
On the other hand, utilize this nginx -s command:
- sudo nginx -s restart
Stop Nginx
Use the next commands to shut down or stop Nginx service:
- sudo /etc/init.d/nginx stop
Another option is to utilize:
- sudo nginx -s stop
Reloading Nginx
Nginx and associated processes can be properly stopped nginx and restarted by using the following command:
- sudo /etc/init.d/nginx reload
If you’d rather give Nginx directions straight away, you can do this by using the nginx -s command:
- sudo nginx -s reload
Quit Nginx
By combining the quit command alongside the nginx -s command, you can force the Nginx service to end:
- sudo nginx -s quit
Start, Stop and Reload Nginx using SysVinit
The Nginx daemon gets started, stopped, and restarted utilizing init.d scripts in previous (EOLed) editions of Ubuntu, CentOS, as well as Debian.
Restarting the Nginx service
- sudo service nginx restart
Starting the Nginx services
- sudo service nginx start
Terminate the Nginx service
- sudo service nginx stop
Also Read: How to Use apt-get reinstall on Debian and Ubuntu?
Summing Up
Several techniques on how to start, stop, and restart Nginx on your server have been described in this post. If you’re administering an Nginx web server, utilize the commands mentioned above for the tasks that come up the most often.