How to start stop restart reload nginx on linux

It can be quite frustrating not knowing how to mangage your server. I’ve been in the situation myself just for a reminder i’ve listed all the commands here how you can start, stop, reload or restart your server.

Sample commands nginx

This quide gives a bisic introduction and describes some simple tasks that can be done with it. We assume you’ve already installed nginx on your machine.The following signals are available:

  • start — startup
  • stop — fast shutdown
  • quit — graceful shutdown
  • reload — reloading the configuration file
  • restart — restart the configuration file
  • reopen — reopening the log files

I’ve listed the most popular ways of managing your server in linux below, keep in mind that you’ll have to replace the word signal with the correct signal for your needs. I’ve listed all the possibilities above.

sudo service nginx signal

Or

sudo /etc/init.d/nginx signal

Or

sudo nginx -s signal

Once the master process receives the signal to reload configuration, it does an internal check of syntax and validity of the new configuration file. If this validation is a success, the master process starts the new worker processes and sends messages to old worker processes, requesting them to shut down. If the validation is not successful the master process rolls back the changes and continues to work with the old configuration. Old worker processes, receiving a command to shut down, stop accepting new connections and continue to service current requests until all such requests are serviced. After all the requests are processed the old worker processes exits.

Testing configuration for syntax and validity

You can manually check the configuration for syntax errors with the -t parameter. Remember that you’ll have to execute this command with the same user you’ve configured nginx.

sudo nginx -t

example output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

You can read more about nginx here.

You may also like...