...

Open source softwares - NGINX

Back to Course

Lesson Description


Lession - #618 Starting and Restarting NGINX


Starting and Restarting NGINX

Following are the list of some of the basic manipulation commands to start, stop, restart or reload the Nginx. Start Nginx: Nginx can be started from the following command line:

$ sudo systemctl start nginx  


This command does not produce any output. If you are using a Linux distribution without systemd then to start Nginx, type the following command:

$ sudo service start nginx  


Or for older Ubuntu Linux version:

sudo /etc/init.d/nginx start  


Enable Nginx Service:

The above order just beginnings the assistance for the interim. We need to begin it physically after each reboot. Rather than physically beginning the Nginx administration, it is prescribed to empower it auto-start at boot season of the framework. To empower the Nginx administration, utilize the following command:

$ sudo systemctl enable nginx  


Or if you are using a Linux distribution without systemd then use the following command:

$ sudo service nginx enable  


Stop Nginx

Stoping Nginx will straightforwardly close down all Nginx specialist processes regardless of whether there are open associations. We can stop the Nginx cycle in two ways. The primary way is to call Nginx with the stop order. Utilize one of the following commands to stop the Nginx:

$ sudo systemctl stop nginx  

Or if you are using a Linux distribution without systemd then use the following command: $ sudo service stop nginx Or nginx compiled and installed from the source code: $ sudo /usr/bin/nginx -s stop Or for older Ubuntu Linux version: $ sudo /etc/init.d/nginx stop The second way to stop Nginx is to send a signal to the Nginx master process. By default, Nginx stores its master process id to /usr/local/nginx/logs/nginx.pid. Here is the command to send the QUIT (Graceful Shutdown>
signal to the Nginx master process: $ kill -QUIT $( cat /usr/local/nginx/logs/nginx.pid >


Restart Nginx

The restart option is quick action of stopping and then starting the Nginx server. Use one of the following commands to restart the Nginx: $ sudo systemctl restart nginx Or if you are using a Linux distribution without systemd then use the following command: $ sudo service restart nginx Or for older Ubuntu Linux version: sudo /etc/init.d/nginx restart

Reload Nginx

We need to restart or reload Nginx whenever we make changes to its configuration. The reload option will load the new configuration, start new worker processes with the new configuration and gracefully shut down old worker processes. To reload the Nginx, type one of the following commands: $ sudo systemctl reload nginx Or if you are using a Linux distribution without systemd then use the following command: $ sudo service reload nginx

Test Nginx Configuration

Whenever we make changes or edit something to the Nginx server's configuration file, it is a good idea to test the configuration before restarting or reloading the service. Use the following command to test the Nginx configuration for any syntax or system errors: $ sudo nginx -t Or service nginx configtest The output of both will look something like this:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If there is any error these commands will print a detailed message.