If you’re like most webmasters, you probably know that nginx is a powerful and efficient web server. But if something goes wrong with it, restarting nginx can be a frustrating experience. In this article, we’ll show you how to restart nginx in the easiest way possible. ..
The solution is to use the graceful restart feature to get the web server process to read in the new configuration changes without taking the server down. Luckily nginx, Apache, PHP-FPM, and many other services support this.
What actually happens is that nginx starts a new process with a new set of worker processes that accept requests, and the old worker processes are instructed to gracefully shut down. So any new visitors that come to your site won’t have to wait for the whole thing to restart.
Restart nginx Gracefully
There are multiple ways to do this, depending on what operating system you are using, but the one method that works on every platform is to just pass the reload signal to the nginx process directly. The -s argument to nginx is for passing a “signal” and that signal is “reload”.
This will only work if the nginx sbin directory is in your path, so realistically you’ll need to use the full path like this:
It’s worth noting that you should probably test the nginx configuration before you pass the reload command — you can do that with “nginx -t”.
You can also reload using the service command on distributions that support it (like Ubuntu or Debian). So the command would be this:
Pretty simple.