Basic Nginx Commands

This short tutorial covers a few basic commands or tasks that can be performed with Nginx from the commandline. Understanding the basic commands is the first step to understanding how to manage Nginx on your server. You can invoke the Nginx executable using the -s paramTeter. The correct syntax is as follows:

nginx -s signal

Common Commands

– stop – Shutdown Nginx fast
– quit – Shutdown Nginx gracefully
– restart – Restarts Nginx while also applying any current configurations.
– reload – forces a reload of the configuration file

Stop Command

Let’s say we wanted to stop Nginx right away without finishing the current worker processes. We would use the “stop” command like this:

nginx -s stop

Reload Command

Keep in mind, if you edit the configuration file for Nginx it will not be used or applied until the reload command is invoked or you restart Nginx. To force a reload of Nginx, run the command:

nginx -s reload

Once the reload command is ran a signal is sent to the master process. It then checks the syntax of the new configuration file and attempts to apply it. If this is successful, the master process will start new child processes using the new configuration. Old child processes still running will be sent a command to end the current process and restart using the new configuration.

If the new configuration is found to be invalid, the master process will roll back changes and will continue to use the old configuration. This is a great feature as you’ll never be able to stop the current configuration and replace it with an invalid one.

Leave a Reply