Depending on the system that you have, it will offer one clean way of reloading your Nginx setup
Debian based:
/etc/init.d/Nginx reload
Fedora based:
service Nginx reload
FreeBSD/BSD:
service Nginx reload
Windows:
Nginx -s reload
All the preceding commands reload Nginx; they send a HUP signal to the main Nginx process. You can send quite a few control signals to the Nginx master process, as outlined in the following table. These let you manage some of the basic administrative tasks:
Signal |
Activity |
---|---|
Quick shutdown | |
Graceful shutdown | |
Reload configuration, gracefully shutdown the worker processes and restart them | |
Reopen the log files | |
Upgrade the executable on the fly, when you have already installed it | |
Gracefully shutdown the worker process |
Let me run you through the simple steps of how you can reload Nginx from the command line.
Open a terminal on your system. Most UNIX-based systems already have fairly powerful terminals, while you can use PuTTY on Windows systems.
Type in
ps auxww | grep nginx
. This will output something as shown in the following screenshot:If nothing comes, then it means that Nginx is not running on your system.
If you get the preceding output, then you can see the master process and the two worker processes (it may be more, depending on your
worker_processes
configuration). The important number is3322
, which is basically the PID of the master process.To reload Nginx, you can issue the command
kill -HUP <PID
of
the
nginx
master
process>
. In this case, the PID of the master process is3322
. This will basically read the configurations again, gracefully close your current connections, and start new worker processes. You can issue anotherps auxww | grep nginx
to see new PIDs for the worker processes (4582,4583):If the worker PIDs do not change it means that you may have a problem while reloading the configuration files. Go ahead and check the Nginx error log.
This is very useful while writing scripts, which control Nginx configuration. A good example is when you are deploying code on production; you will temporarily point the site to a static landing page.