Javatpoint Logo
Javatpoint Logo

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:

This command does not produce any output.

If you are using a Linux distribution without systemd then to start Nginx, type the following command:

Or for older Ubuntu Linux version:

Enable Nginx Service:

The above command only starts the service for the meantime. We have to start it manually after each reboot.

Instead of manually starting the Nginx service, it is recommended to enable it auto-start at boot time of the system. To enable the Nginx service, use the following command:

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

Stop Nginx

Stopping Nginx will directly shut down all Nginx worker processes even if there are open connections. We can stop the Nginx process in two ways.

The first way is to call Nginx with the stop command. Use one of the following commands to stop the Nginx:

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

Or nginx compiled and installed from the source code:

Or for older Ubuntu Linux version:

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:

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:

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

Or for older Ubuntu Linux version:

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:

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

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:

Or

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.






Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA